This is helpful if you've previously installed git from source on OSX, and other compilers can't find the correct path. You need to remove the current version of git, then re-install with brew.
-
Check which git you're running:
which git
output should be similar to this: /usr/bin/git
-
Remove that git install
sudo rm -rf /usr/bin/git/ sudo rm /etc/paths.d/git sudo rm /etc/manpaths.d/git sudo pkgutil --forget --pkgs=GitOSX\.Installer\.git[A-Za-z0-9]*\.[a-z]*.pkg
brew uninstall git
brew update
brew install git
Check which git you're now running:
which git
Should now say: /usr/local/bin/git
@martbe, Thank you! You have clarified the problem and I can see now why this has caused so much confusion. I'm going to edit my answer above.
The real culprit here is that the terminal needs to be reloaded after you run
brew install git
just like you said.The reason this causes confusion is because it's not always necessary to restart your terminal when installing things with brew but this is a special case due to Xcode and the terminal where, even if your
$PATH
seems correct, the incorrect path togit
will be used unless you restart your terminal. Re-sourcing ~/.bash_profile or the like won't work either. The terminal must be restarted after you runbrew install git
.The longer explanation of how this can cause confusion is below.
In my case, since I've already installed homebrew's git, I want to get my system back to the original state so I can show where confusion happens when you install with homebrew. You may not yet have installed with homebrew so skip to the "Install Git with Homebrew alongside Xcode's Git installation" step below.
Uninstall brew's git:
Confirm that terminal sees old Xcode version of git.
Install Git with Homebrew alongside Xcode's Git installation
Here it is assumed that we have a version of git that has been installed by Xcode and we want to install a new version using homebrew.
Install git with brew.
Confirm that brew installed a new version of git... and here is where the confusion begins...
Wait, what? This is the same old Xcode version we saw before.
It seems that brew didn't install a new version of git. Do some digging.
Run
which git
to see if new version of git is properly found in our path.Okay, that's correct path and the
which
command returns the first one found in your path so why wouldn'tgit --version
work?Dig a little further just to confirm that brew worked properly. Did brew install a new version of git?
-or-
So it seems brew did install a new version of git. What's happening?
Since
which git
showed the above brew path to git, it should be the one that's used when runninggit --version
, i.e., it should be the new version/same as above but we're still seeing same problem after we've confirmed brew installed git properly.Go a little further and check for all git programs in our path this time and see their versions.
Ensure that
/usr/local/bin
is ahead of/usr/bin
in $PATH even though we already know this to be the case.So our paths are correct which we essentially already knew...
This is where some people, including me, might set and forget something like
alias git=/usr/local/bin/git
to ~/.bash_aliases or add/usr/local/bin/git
to$PATH
without realizing that simply opening a new terminal and then runninggit --version
will show the newly installed git from homebrew.So for me, that's all that was needed all along. I can see from the above how it would be easy to get confused and simply set and forget an alias or equivalent, and that's still rather harmless, but it's still good to understand the real fix.