Which Git? How to Keep Git Up To Date on Mac

As we all know the majority of the Web development community uses Git. The funny part to the whole story is the fact that most developers don’t even know what version they’re using.

Before I get up on my high horse I’ll preface everything by saying I was in the same boat as the rest of you. Sadly, making sure my version of Git is up to date is the last thing on my mind. Thankfully I’ve grown up since those troubled days and finally realize the value of keeping Git up to date and using the best techniques to keep it that way.

When we install Git for mac via Xcode >=4 command line tools or the Native OS, it points Git to your usr/bin directory. This is a huge pita as Git never updates automatically and you’re always dependent on the version of Git you’ve installed based on the last time you’ve updated Xcode command line tools or installed Git locally on your machine. This is more of a general problem that you would encounter with a lot of other tools too. The best practice is to always have /usr/local/bin in use before /usr/bin in order to use newer versions of Git, Python, Ruby, etc than the host OS provides. This is especially apparent if you’re using Homebrew, which should warn and help you with this.

Wanna know what version of Git you got? Open your cli of choice and type:

which git

This line will report back where Git is installed on your machine. For me it says the following:

/usr/local/bin/git

Great for me, but you still might see something like this:

/usr/bin

What version of Git am I using?

git --version

So how do we fix this? In order to stop this nonsense we have to alter a dot file and specifically the .bash_profile (located in your “user” directory of your machine –for example mine is “GrayGhostVisuals“– with the following:

export PATH=/usr/local/bin:$PATH 

This little one liner allows us to update Git and use the Homebrew installation instead of our Native OS’. This results in usr/bin to point at usr/local/bin/git. Now all we need to do is install git via brew.

brew install git

Wanna keep git up to date? Easy peezy 123:

brew upgrade git

You’re now part of the wonderful esoteric world of the developers that actually know how to keep Git up to date. Cheers!

Them sweet, sweet links!

GrayGhost

Web Development & Design, Technical Writing, Interaction Design, Open Source Maker & Contributor. Helping Create A Better Web. http://grayghostvisuals.com.
  1. ❧ Brian Tully shouted:
    2013/04/03 • 3:19 pm

    Love your site! Very inspiring and informative. I just wanted to give you a heads up on a typo for the last brew command in this article.

    brew update git

    should actually be:

    brew upgrade git

    Thanks again for all your awesome help and information!

    1. Awesome spot Brian! Thanks so much for the correction and the kind words \m/

  2. Great – except this didn’t work for me (my old version of git was working fine, it seemed, but when I went to install the Github for Mac app, it said my git was out of date).

    The error I got is one I’ve seen before with homebrew. I’d rather avoid getting it in the first place:

    Error: The `brew link` step did not complete successfully
    The formula built, but is not symlinked into /usr/local
    1. Might be a permission issue (https://github.com/Homebrew/homebrew/issues/11184) or possibly a dotfile configuration. What happens when you run the following?

      brew doctor
      1. brew doctor gave me a lot of warnings, of course so I tried this:

        $ sudo brew link git
        Linking /usr/local/Cellar/git/2.0.4... 
        Error: Could not symlink share/git-core/templates/description
        Target /usr/local/share/git-core/templates/description
        already exists. You may want to remove it:
        rm /usr/local/share/git-core/templates/description
  3. Thank you for this.

  4. Thank you very much!

Leave a Reply

Your email address will not be published. Required fields are marked *

show formatting examples
<pre class="language-[markup | sass | css | php | javascript | ruby | clike | bash]"><code>
…code example goes here…
</code></pre>

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Comment Preview

  1. John Doe shouted this comment preview:
    2013/02/19