Install Git on Mac OS X

There are several ways to install Git on a Mac. In fact, if you’ve installed XCode (or it’s Command Line Tools), Git may already be installed. To find out, open a terminal and enter.git --version

$ git --version
git version 2.7.0 (Apple Git-66)

Apple actually maintains and ship their own fork of Git, but it tends to lag behind mainstream Git by several major versions. You may want to install a newer version of Git using one of the methods below:

Git for Mac Installer

The easiest way to install Git on a Mac is via the stand-alone installer:

  1. Download the latest Git for Mac installer.
  2. Follow the prompts to install Git.
  3. Open a terminal and verify the installation was successful by typing git --version:
    $ git --version
     git version 2.9.2
  4. Configure your Git username and email using the following commands, replacing Emma’s name with your own. These details will be associated with any commits that you create:
    $ git config --global user.name "Emma Paris"
     $ git config --global user.email "eparis@atlassian.com"
  5. (Optional) To make Git remember your username and password when working with HTTPS repositories, configure the git-credential-osxkeychain helper.

Install Git with Homebrew

If you have installed Homebrew to manage packages on OS X, you can follow these instructions to install Git:

  1. Open your terminal and install Git using Homebrew:
    $ brew install git
  2. Verify the installation was successful by typing which git --version:
    $ git --version
     git version 2.9.2
  3. Configure your Git username and email using the following commands, replacing Emma’s name with your own. These details will be associated with any commits that you create:
    $ git config --global user.name "Emma Paris" 
     $ git config --global user.email "eparis@atlassian.com"
  4. (Optional) To make Git remember your username and password when working with HTTPS repositories, install the git-credential-osxkeychain helper.

Install Git with MacPorts

If you have installed MacPorts to manage packages on OS X, you can follow these instructions to install Git:

  1. Open your terminal and update MacPorts:
    $ sudo port selfupdate
  2. Search for the latest available Git ports and variants:
    $ port search git
     $ port variants git
  3. Install Git with bash completion, the OS X keychain helper, and the docs:
    $ sudo port install git +bash_completion+credential_osxkeychain+doc
  4. Configure your Git username and email using the following commands, replacing Emma’s name with your own. These details will be associated with any commits that you create:
    $ git config --global user.name "Emma Paris"
     $ git config --global user.email "eparis@atlassian.com"
  5. (Optional) To make Git remember your username and password when working with HTTPS repositories, configure the git-credential-osxkeychain helper.

Install the git-credential-osxkeychain helper

Bitbucket supports pushing and pulling your Git repositories over both SSH and HTTPS. To work with a private repository over HTTPS, you must supply a username and password each time you push or pull. The git-credential-osxkeychain helper allows you to cache your username and password in the OSX keychain, so you don’t have to retype it each time.

  1. If you followed the MacPorts or Homebrew instructions above, the helper should already be installed. Otherwise you’ll need to download and install it. Open a terminal window and check:
    $ git credential-osxkeychain
     usage: git credential-osxkeychain <get|store|erase>

    If you receive a usage statement, skip to step 4. If the helper is not installed, go to step 2.

  2. Use curl to download git-credential-osxkeychain (or download it via your browser) and move it to /usr/local/bin:
    $ curl -O http://github-media-downloads.s3.amazonaws.com/osx/git-credential-osxkeychain
     $ sudo mv git-credential-osxkeychain /usr/local/bin/
  3. Make the file an executable:
    $ chmod u+x /usr/local/bin/git-credential-osxkeychain
  4. Configure git to use the osxkeychain credential helper.
    $ git config --global credential.helper osxkeychain

    The next time Git prompts you for a username and password, it will cache them in your keychain for future use.

Install Git with Atlassian Sourcetree

Sourcetree, a free visual Git client for Mac, comes with its own bundled version of Git. You can download Sourcetree here.

To learn how to use Git with Sourcetree (and how to host your Git repositories on Bitbucket) you can follow our comprehensive Git tutorial with Bitbucket and Sourcetree.

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s