Sunday, April 26, 2015

Frustration of the Week: How to Overwrite Apple Git (old version) with Homebrew Git (newer version)

So you've got two versions of Git on your Apple machine: the Apple-installed version and the Homebrew version. Unfortunately, the Apple version is outdated, and your computer won't stop using that one instead of your shiny new Homebrew version. You know because when you type git --version into the command line, you see the old version showing up instead of the new one. Rats!

Entering:
export PATH=/usr/local/bin:$PATH
and then
git --version
will temporarily get your console to show the updated version. But once you exit out of the Terminal and reopen the Terminal, your computer will go back to its old ways again.

That means that

which git
tells you

/usr/bin/git
instead of

/usr/local/bin/git
You want /usr/local/bin/git because that is where the newer version is installed.

Why, computer gods, why??

It's really quite simple. Your computer does not hate you. It's just following the instructions located in its .bash_profile.

To tell it what you want it to do, you need to edit your bash profile.

In Terminal, type the following commands:

cd
touch .bash_profile
open -a "TextEdit" .bash_profile
Your .bash_profile will open in TextEdit. Add this line to the file:
export PATH="/usr/local/bin:$PATH"
Save it and enter this in the Terminal to finalize the change:
source .bash_profile
Now you have to link your Homebrew git, by saying 
brew link git

Now (FINALLY), which git should say /usr/local/bin/git

...which is where Homebrew's updated git version should be located. Success!

Now every time you need to update your git, you just say:

brew update
brew upgrade git
That's it! Awesome.

A million thanks to the kind helpers who shared their wisdom via the following threads:
http://superuser.com/questions/409501/edit-bash-profile-in-os-x
http://superuser.com/questions/708601/homebrew-cant-link-git