If, when you run "git --version", you see a message like "git version 1.9.3 (Apple Git-50)" you have a version of Git from Apple. The version in this example is 1.9.3, while 2.2.1 is the current latest release. We want to use the latest release, so let's check to see if we also have an official version installed that just isn't getting priority over the version from Apple.

Checking for an existing Git installation

Run "ls /usr/local" and look through that list to find git.

If you don't see git in that list, you most likely don't have it installed and should stop watching this video, and instead, watch Updating Git if You Have Only the Version That Comes with Xcode or the Command Line Developer Tools.

If you do see git in this list, like I do here, you should continue watching this video.

Giving the official version priority over the one from Apple

So, I've confirmed that I have an official version of Git installed on my system but, when I try to run "git --version" it still says I'm using "git version 1.9.3 (Apple Git-50)". This is simply because the path "/usr/local/git/bin" comes after the path used by the apple version of Git in my PATH variable. So, I just need to update my PATH variable and make sure that the path to the official version comes before the path to the version installed by Apple.

You can see what the PATH includes by typing "echo $PATH" and pressing Enter. When I do that, you'll notice that "/usr/local/git/bin" is the last one in the list. I'll update it using VI. (If you're not familiar with VI, I'd encourage you to checkout the "Command Line Basics" series on this site to get familiar with it.)

Before I proceed, I want to mention that what we're going to do could be harmful to your machine if done improperly. We'll be using "sudo", (which stands for super user do) which allows you to perform actions that standard users are not allowed to, in order to protect them from accidentally messing up their systems. If you follow these steps precisely, you won't be at risk, but please do not start using "sudo", or editing system files if you're not exactly sure what you are doing.

Okay, with that disclaimer out of the way, let's continue.

  • I'll type "sudo vi /etc/paths"

When you do this for the first time, you'll get this message:

WARNING: Improper use of the sudo command could lead to data loss
or the deletion of important system files. Please double-check your
typing when using sudo. Type "man sudo" for more information.

To proceed, enter your password, or type Ctrl-C to abort.

  • I do want to proceed, so I'll enter my password, and press Enter
  • Press "i" to enter "Insert" mode
  • Type "/usr/local/git/bin" and press Enter to move the original first line to the second line
  • Press esc (The escape key)
  • Type ":wq"
  • Press Enter

At this point, if you have any terminal sessions open, you'll need to close them and reopen them in order to pickup the new PATH. I'll go ahead and just quit iTerm and re-open it to get a fresh start. Now, we can check our PATH variable by typing "echo $PATH" and pressing Enter. When we do that, we'll see "/usr/local/git/bin" at the beginning of the list.

Now, when we type "git --version", we see the message "git version 2.0.1". So, the official release is taking precedence over the version from Apple, but the latest release is 2.2.1, so now, I need to update Git to the latest release.

Updating the official version of Git

Before we begin the installation process, I'll open up the README.txt file that comes with the disk image. I'll walk you through these steps now, but it's a good idea for you to open this up and read through it yourself in case there's an update in the future.

Uninstalling the current version of Git

According to the README.txt file, to upgrade your version of Git, you should first uninstall the old version using the uninstall.sh script included in the download. I'll do that now.

  • I'll simply drag the "uninstall.sh" file from the disk image onto my terminal window. (This loads the path to the script in the terminal.)
  • Then, switch to the terminal and press Enter
  • When asked if I'm sure I want to uninstall, I'll type "yes" and press Enter
  • Then, enter my password and press Enter one last time

Now, the old version of git is uninstalled and we can verify it by typing "ls /usr/local". Since it's uninstalled, we don't see it in the list here.

Now we can install the version we just downloaded.

Installing the latest release of Git

  • Double click the ".pkg" installer file
  • If presented a pop up saying that cannot be installed because it is from an unidentified developer, you can override this security feature for this application only.
    * Click OK
    * Right-click (or hold the control key and click) on the ".pkg" file and select "Open"
    * Now, select Open
  • Click "Continue" to begin the installation process
  • Then, click install
  • You may be asked for your administrator password. Type it in and click "Install Software".
  • Once the installation is complete, click "Close".
  • The next step in the README.txt file is to restart bash sessions. I'll simply quit iTerm, and re-open it. If you have any terminal windows, GNU Screens or TMUX sessions open, you'll need to restart those, or run "source /etc/profile" in each of them.

The final step is optional, and allows non-terminal applications to see Git. There's no harm in running it, and you may find it useful in the future, so I'm going to go ahead and run the script.

  • Switch back to Finder, and drag the "setup git PATH for non-terminal programs.sh" file into your terminal window. (This loads the path to the script in the terminal.)
  • Press Enter
  • Finally, you need to logout of your Mac OSX user account and log back in. (A restart would also work.)

Now, when I open up iTerm type "git --version", we see the message "git version 2.2.1". So, we're ready to go!