How to upgrade Git to latest version on OS X?

I just bought a new Mac with OS X Lion and I checked in the Terminal what version of git is installed by default. I got the answer

git --version
> git version

I would like to upgrade git to the latest version, so I downloaded the dmg installer “git-” and I launched it.

  • Is it possible to set git clone to always use --reference?
  • Hosting a Repository website on Github not working?
  • Apache and git-http-backend
  • How do I clone a git repo taking only a subset of branches and no history only the head of each branch
  • How to get the last push date or file modification date when deploying to Heroku?
  • vim bundles are not installed by vundle exactly in Puppet
  • After the install, the Terminal still says that the version is What am I doing wrong?

  • git - how to get default branch?
  • How do you integrate Phabricator and Git or SVN
  • How to check if remote branch exists on a given remote repository?
  • Git Version numbering with a centralized workflow
  • Can't push to ssh based git repository
  • Deploying with github, git_discovery_across_filesystem not set
  • 10 Solutions collect form web for “How to upgrade Git to latest version on OS X?”

    It would probably be better if you added:

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

    to a file named .bashrc in your home folder. This way any other software that you might install in /usr/local/git/bin will also be found first.

    For an easy way to do this just type:

    echo "export PATH=/usr/local/git/bin:/usr/local/sbin:$PATH" >> ~/.bashrc

    into the Terminal and it will do it for you.

    I recently upgraded the Git on my OS X machine to the latest also. I didn’t use the same .dmg you used, but when I installed it the binaries were placed in /usr/local/bin. Now, the way my PATH was arranged, the directory /usr/bin appears before /usr/local/bin. So what I did was:

    cd /usr/bin
    mkdir git.ORIG
    mv git* git.ORIG/

    This moves the several original programs named git* to a new subdirectory that keeps them out of the way. After that, which git shows that the one in /usr/local/bin is found.

    Modify the above procedure as necessary to fit wherever you installed the new binaries.

    After searching for “trouble upgrading git on mac” on Google, I read several posts and attempted the following before resolving the problem by completing step 4:

    1. I updated my terminal path by using the above mention export command. Every time I quit the terminal and restarted it, when I typed git --version the terminal, it still return the older version 1.8.

    2. I followed the README.txt instructions for upgrading to the current version 2.0.1 that comes with the .dmg installer and when I restarted the terminal, still no go.

    3. I looked for /etc/path/ folder as instructed above and the directory called “path” does not exist on my Mac. I am running OS X Mavericks version 10.9.4.

    4. Then I recalled I have Homebrew installed on my Mac and ran the following:

      brew --version
      brew update
      brew search git
      brew install git

    This finally resolved my problem. If anyone has some insight as to why this worked, further insight would be greatly appreciated. I probably have some left over path settings on my system from working with Ruby last year.

    The installer from the git homepage installs into /usr/local/git by default. However, if you install XCode4, it will install a git version in /usr/bin. To ensure you can easily upgrade from the website and use the latest git version, edit either your profile information to place /usr/local/git/bin before /usr/bin in the $PATH or edit /etc/paths and insert /usr/local/git/bin as the first entry.

    It may help to someone at-least changing the order in /etc/paths worked for me.

    if using homebrew you can update sim links using

    brew link --overwrite git

    the simplest way I found so far is from git official website.
    It just computed dependencies and downloaded all of the required libraries/tools

    The other major way is to install Git via MacPorts
    ( If you have MacPorts installed, install Git

    $ sudo port install git-core +svn +doc +bash_completion +gitweb

    I prefer not to alter the path hierarchy, but instead deal with git specifically…knowing that I’m never going to use old git to do what new git will now manage. This is a brute force solution.

    NOTE: I installed XCode on Yosemite (10.10.2) clean first.

    I then installed from the binary available on

    $ which git
    $ cd /usr/bin
    $ sudo ln -sf /usr/local/git/bin/git
    $ sudo ln -sf /usr/local/git/bin/git-credential-osxkeychain
    $ sudo ln -sf /usr/local/git/bin/git-cvsserver
    $ sudo ln -sf /usr/local/git/bin/git-receive-pack
    $ sudo ln -sf /usr/local/git/bin/git-shell
    $ sudo ln -sf /usr/local/git/bin/git-upload-archive
    $ sudo ln -sf /usr/local/git/bin/git-upload-pack
    $ ls -la
    (you should see your new symlinks)

    Without Homebrew

    1. Use the installer from git’s website.
    2. Update your ~/.bash_profile file. Notice this command differs from kmikael’s answer by what it puts in the file:
      • Other command: export PATH=/usr/local/git/bin:/usr/local/sbin/:[and so on]
      • Below command: export PATH="/usr/local/git/bin:/usr/local/sbin:$PATH"
      • Use whichever one you prefer.

    echo 'export PATH="/usr/local/git/bin:/usr/local/sbin:$PATH"' >> ~/.bash_profile

    1. If you’re using Xcode, you’ll need to add some symbolic links.
      • Example: ln -s /opt/local/bin/git /usr/bin/git
    2. Restart terminal.
      • which git should say the directory in the README.txt file from the dmg.
      • git --version should say the updated version.
      • echo $PATH should start with /usr/local/git/bin:/usr/local/sbin:

    I did it in this way:

    1. Open GitHub application installed on Mac
    2. Click on Advanced tab → Install command line tools
    3. Once you get a message that all commands have been installed close your terminal and reopen it.
    4. Now check git --version, it should give you the latest version.

    In order to keep both versions, I just changed the value of PAHT environment variable by putting the new version’s git path “/usr/local/git/bin/” at the beginning, it forces to use the newest version:

    $ echo $PATH


    $ git –version

    git version 2.4.9 (Apple Git-60)

    original value: /usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/X11/bin:/usr/local/git/bin/

    new value: /usr/local/git/bin/:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/X11/bin

    $ export PATH=/usr/local/git/bin/:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/X11/bin

    $ git –version

    git version 2.13.0

    Git Baby is a git and github fan, let's start git clone.