override git from Xcode with homebrew version override git from Xcode with homebrew version xcode xcode

override git from Xcode with homebrew version


Xcode is actually using the GIT that is stored in /Applications/Xcode.app/Contents/Developer/usr/bin. The same version of GIT gets installed in /usr/bin when you installed the command line tools as part of Xcode installation. So, you won't be able to change what Xcode is using (unless you are willing to muck with the contents of the Xcode package). If, from a terminal application, you want to use the homebrew-installed GIT then you have two options:

  1. Reference GIT with the full path as /usr/local/bin/git ... For this case you can create an alias like alias mgit=/usr/local/bin/git and then use mgit ... from the terminal
  2. Change the path as PATH=/usr/local/bin:$PATH either in your .bashrc or .zshrc if you use zsh file (or each time you start a terminal at the command line).


Since Xcode hard coded its own version of git which is installed on /Applications/Xcode.app/Contents/Developer/usr/bin/git, I managed to use this work around trick:

  1. change into the Xcode directory:

    cd /Applications/Xcode.app/Contents/Developer/usr/bin

  2. rename the Xcode's git like this:

    sudo mv ./git ./git-xcode-usr-bin

  3. link my own git which is installed through homebrew:

    sudo ln -s /usr/local/bin/git ./git

And I did the same thing with /usr/bin/git

This will acctually link /usr/local/Cellar/git/1.8.0/bin/git (because I'm use git 1.8.0 at the present)

Certainly this may cause some other problems, such as when I upgrade the homebrew's verion git in the future, it would not work for me :( and I have to make a new link then.

I do it like this because I want to solve my own problem here 13177203. And after search StackOverFlow for a long time, I finally got this solution.


If you are using fish shell instead of bash, you can point to your preferred git binary by adding the following to ~/.config/fish/config.fish.

function git  /usr/local/bin/git $argv; end