Shorter answer.
No need to uninstall the Xcode git
you are seeing in Mac OS X. Just add /usr/local/git/bin
to your $PATH
by editing ~/.bash_profile
to add an export PATH
like this:
export PATH="/usr/local/git/bin:$PATH"
Then close and save that file and get that loaded into your Terminal session like by typing this:
source ~/.bash_profile
And the newly installed git
will be accessible to you in preference over the Xcode installed git
you already have.
Longer answer.
Interpreting the error message.
The issue can be understood by looking at the contents of the uninstall.sh
Bash script that comes with the official Git installer package for Mac OS X to see exactly what it does. Here is the snippet near the top that throws the error you are seeing:
#!/bin/bash
if [ ! -r "/usr/local/git" ]; then
echo "Git doesn't appear to be installed via this installer. Aborting"
exit 1
fi
Note the line if [ ! -r "/usr/local/git" ]; then
, the Bash script is checking for the existence of this directory path:
/usr/local/git/
But when you ran which git
the path directory path you got was:
/usr/bin/
That indicates that the official installer installs git
its items in /usr/local/git/
and not in core Mac OS X directory of /usr/bin/
.
Then what is that other version of git
you already have in place? Let’s check the output of git --version
for more details:
$ git --version
git version 1.7.9.6 (Apple Git-31.1)
You see that (Apple Git-31.1)
? That indicates it was installed by Apple. And since git
is not a part of the core Mac OS X setup, the only way this could have been installed was via Xcode and related command line binaries.
So in short you cannot—and should not—attempt to uninstall the Xcode version of git
. Instead you want to make your Terminal favor the git
binaries installed in /usr/local/git/bin/
over the core Mac OS X binaries in /usr/bin/
. And you can do this by modifying your $PATH
setting in ~/.bash_profile
like this.
Fixing the issue.
First, open up ~/.bash_profile
in a text editor. I prefer to do this directly in the command line using nano
like this:
nano ~/.bash_profile
Now if no export $PATH
exists in that ~/.bash_profile
, just add a $PATH
line like this to the file:
export PATH="/usr/local/git/bin:$PATH"
If an export $PATH
does exist there, do a modification to that value to get /usr/local/git/bin
to be before the main $PATH
of the system. Note the :
delimiter.
Now close and save that file and get that loaded into your Terminal session like by typing this:
source ~/.bash_profile
Now if you type in:
which git
The output should be:
/usr/local/git/bin/git
Which means that your Terminal $PATH
will now check in /usr/local/git/bin/
before it moves on to check other directories in it’s default $PATH
values for the git
binary.
So without uninstalling the Xcode version of git
you can now download and install the official—and updated—git
binary and use it without dealing with Homebrew or anything else. For example, on my system this is the current output of git --version
is as follows:
git version 2.5.3
No (Apple Git-31.1)
in sight. Just a pure, git
version number that is up to date and ready to use thanks to this $PATH
adjustment.