Git SCM does not comes out-of-the-box(OOTB) with Mac OS X. However if you have installed Xcode command line tools or standalone Git Installer then you will have Git SCM on Mac OS X.
Warm Up!
Let’s check existing Git version on your machine.
Scenario 1: You will get similar to this version!
1 2 3 |
mac-book-pro:~ jeeva$ git --version git version 1.7.7.5 (Apple Git-26) |
OR
Scenario 2: you may get like this
If you get below message nothing to worry; it means you have not yet installed Git SCM on your machine
1 2 3 |
mac-book-pro:~ jeeva$ git --version -bash: git: command not found |
Let’s start Git upgrade
First thing, get the latest Git SCM for Mac OS X Click here to Download(from git-scm.com). You will get .dmg file. In this article I’m using current latest version of Git SCM 1.7.11.3 for upgrade!
- Open the downloaded git-x.x.x.x-intel-universal-snow-leopard.dmg
- You will see uninstall.sh, Run this shell script (if you have scenario 2 on your machine, skip this step)
- Run the
git-x.x.x.x-intel-universal-snow-leopard.pkg installer and follow the installer instruction
- This installs the Git in /usr/local/git (root access is required)
Once you finished the package execution (after, click of ‘Finish‘ button)
Git Upgrade Verification
Restart your bash session. If you wish to preserve your precious screen session, just execute source /etc/profile. Verifying Git version
1 2 3 |
mac-book-pro:~ jeeva$ git --version git version 1.7.11.3 |
Wow, you successfully completed upgrade Git in Mac OS X 🙂
How to handle if I still getting Git old version displayed on my Terminal. I know it may happen, don’t worry I will explain. Follow below instructions.
Adding PATH variable to .bash_profile; open up Terminal.app
1 |
mac-book-pro:~ jeeva$ vim ~/.bash_profile |
Place the below export statement at the end of .bash_profile
1 |
export PATH=/usr/local/git/bin:$PATH |
Save your modified .bash_profile and close the vim editor. Either close and re-open your Terminal or execute below command
1 2 3 4 |
mac-book-pro:~ jeeva$ . ~/.bash_profile Executing Terminal bash profile... mac-book-pro:~ jeeva$ |
Now verify Git version and you’re good to go 🙂
Git for Non-terminal programs (Optional Step/Instruction for you)
Typically Non-terminal programs don’t inherit the system wide PATH and MANPATH variables that your terminal does. If you’d like them to be able to see latest Git for any reason.
Run this shell ‘setup git PATH for non-terminal programs.sh’ from the downloaded .dmg installer
1 2 3 4 5 6 7 8 9 10 11 |
mac-book-pro:~ jeeva$ /bin/sh "/Volumes/Git 1.7.11.3 Snow Leopard Intel Universal/setup git PATH for non-terminal programs.sh" 2012-07-28 14:03:57.593 defaults[5177:707] The domain/default pair of (/Users/jeeva/.MacOSX/environment, PATH) does not exist Variable PATH in ~/.MacOSX/environment.plist changed from '/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:/opt/local/bin' to '/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:/opt/local/bin:/usr/local/git/bin' You will need to log out of your Mac OS X user account and log back in for changes to take effect. ~ ~ ~ mac-book-pro:~ jeeva$ |
Above script will add the PATH and MANPATH to your ~/.MacOSX/environment.plist file.
You’ll need to log out of your user account for that to take effect.