0

I am trying to update git on my Mac OS X 10.8.5 (Mountain Lion).

I downloaded this new version from this link, double-clicked on the .dmg and then dragged uninstall.sh into my terminal (following the instructions there) in order to uninstall the old version and I get:

Git doesn't appear to be installed via this installer.  Aborting

Note that git is currently installed on my computer.

$ git --version
git version 1.7.9.6 (Apple Git-31.1)
$ which git
/usr/bin/git 

Why can't I uninstall? How can I update git?

3 Answers 3

2

On a mac the easiest way is to use homebrew.

  1. Install brew
  2. Follow the instructions (brew doctor will tell you to update your $PATH with /usr/local/bin:$PATH
  3. brew install git

And stop worrying about manual updates, just run brew update && brew upgrade every so often

Why you can't install the existing one:

  • Apple has a default git installation that Xcode uses (in presuming you installed Xcode or at least the command line utilities)
1
  • The key point in this answer is point 2 about the $PATH needing to be changed. Without ever touching Homebrew one can fix this issue by just adjusting the $PATH value. See my answer for more details. Sep 21, 2015 at 8:43
0

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.

-2

Having git installed is simply not enough. Please also remember that git will only work if you're cd'd into a functional git repo folder. This means that you should see a ./.git folder (hint: use ls -la to see hidden folders) and git status should return something similar to the example below:

[some_repo]$ git status
On branch master
Your branch is up-to-date with 'origin/prod'.
nothing to commit, working directory clean

but if the folder is not a valid git repo, you'd see something like this:

[~]$ git status
fatal: Not a git repository (or any of the parent directories): .git
2
  • 2
    Bzzt! Sorry SaxDaddy, but this is answer is about Git usage while the original question is about using a more up-to-date version of Git itself in lieu of the Apple installed Git that comes with Xcode. Sep 21, 2015 at 8:26
  • @JakeGould, my bad and good catch on your part. Thanks for keeping it real
    – SaxDaddy
    Sep 21, 2015 at 8:28

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .