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
@akshajmody
IMPORTANT EDIT - Any solution I wrote in this comment should be ignored unless you've already done the following: restarted your terminal after running
brew install git
(important!), ensuredwhich git
is returning /usr/local/bin/git and that this is what brew installed, confirmed/usr/local/bin/git --version
is displaying the new version installed via brew, and ifgit --version
is still returning the old Xcode version even after restarting your terminal then you can either use simple workarounds to add the path to the proper git install as others and myself mentioned (shown below this edit) or you can use people's solutions above to remove Xcode' git . However it's unlikely any of this is necessary with newer versions of macOS if you've restarted the terminal after installing git with homebrew. For details see @martbe's comment and my comment below it that explains where confusion can happen after installing git with homebrew alongside Xcode's git. For newer versions of macOS, the problem that myself and possibly others experienced is due to simply not restarting the terminal after runningbrew install git
.See above edit before reading further.
If you do
which -a git
you'll notice there are multiple versions of git installed assuming you have one installed from XCode (or straight from git) and another that you've just installed from homebrew.e.g.,
The one in
/usr/local/bin/git
is the one from homebrew which you can confirm withls -al /usr/local/bin/git
and you'll see it's symlinked to the git binary installed in homebrew'sCellar
directory. You can alternatively confirm by passing--version
to each absolute command path to see which is which.When you run a non-absolute command like
git
it will search directories in the$PATH
environment variable and use the first command it finds so you should runecho $PATH
and ensure that/usr/local/bin
comes before/usr/bin
, and if it does then runninggit
should run the correct command for you. Btw, macOS sets up the$PATH
variable this way by default but if you've changed your$PATH
just ensure that/usr/local/bin
comes first.If the above is true and
$PATH
is correct butgit --version
is still running the/usr/bin/git
command then the quickest and simplest fixes are to either:alias git="/usr/local/bin/git"
to~/.bash_aliases
.export PATH=$PATH:/usr/local/bin/git
If that case is happening where $PATH is correctly loading from /usr/local/bin first but
git
is still running the /usr/bin/git command, I think this may have to do with Xcode overriding things but somebody else who's more knowledgeable of Xcode can confirm this since I'm not sure. I've just seen odd things like this before, and it would explain some of these weird cases (and I know Xcode has things likexcrun
to find tools). I'm just not sure. Edit - This could also be related to @martbe's point about reloading terminal, even for older versions, not sure. I'm leaving this be now lol. I've done enough damage!