How to do upgrade Git in Mac OS X?

upgrade git in mac os xGit 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!

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


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

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

Place the below export statement at the end of .bash_profile

Save your modified .bash_profile and close the vim editor.  Either close and re-open your Terminal or execute below command

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

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.

  • I’m running OS X Snow Leopard 10.7.5

    ~$ which git

    /usr/bin/git

    ~$ git –version

    git version 1.7.4.4

    It looks like git is installed and as it should be since I’ve used it for the last year. According to scenario 1, I need to uninstall git and run the script uninstall.sh. So I did…

    ~$ sh uninstall.sh

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

    How else can I uninstall and reinstall git? Is there something I’m missing?

    Thanks for the article!

    • Hello Ben – You’re welcome.
      As per your comment, its a scenario one.

      • After execution of uninstall.sh, restart the terminal
      • Issue a command ‘git –version’, As I mentioned in section ‘Git Upgrade Verification’ if you still get old version of git no issues
      • Proceed with Git installer, complete it
      • After the installation, directory ‘git’ should be present at this path ‘/usr/local/git’
      • Follow the instructions of section ‘Git Upgrade Verification’ in the article for setting up PATH variable
      • Restart the Terminal, Now you should be at latest version of Git

      Please let me know!

      Cheers,
      Jeeva

      • Terseer Shaguy

        Great Jeeva, worked . Many thanks God bless you loads.Amen

  • mem

    Jeeva, absolutely brilliant and clean. Nothing to add. 5 stars post!

    Cheers,

    mem

  • LittleHoopoe

    git –version
    git version 1.8.5.2 (Apple Git-48)

    sh uninstall.sh
    Git doesn’t appear to be installed via this installer. Aborting

    why the uninstaller say that, if git ist already installed?

    • @disqus_siBERhRJpW:disqus It happens sometimes, uninstall.sh may not do its job. Nothing to worry! Proceed with remaining steps, “PATH” settings will ensure; newly installed Git is active for you.

      Try it let me know.

      Cheers,
      Jeeva

      • LittleHoopoe

        thanks for your reply! the rest works fine, I just was irritated of the message. thank you for your help!