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 keep writing 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 command line tools or the native OS, it points git to your usr/bin directory. This is a huge pain in the ass, as git never updates automatically and you’re always dependent on the version of git you’ve installed based on the las 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 never 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 command-line 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
Awesome 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:
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!