Install Git For Mac

Step 1 - Install Git

You can use Git from the command line or you can use one of several GUI-based tools such as Sourcetree. These instructions assume you are using Git from the command-line.

  • Make sure you have root access (sudo) on the system where you want to install Git.
  • Download the Git installer from its official website.
    The installer is a DMG file.
  • Double-click the DMG to expand it.

  • Double-click the PKG file to install it.
    The Git installer launches.
  • Follow the prompts to install Git.
  • Open a terminal on your system.
  • Verify the installation was successful by typing which git at the command line.
    $ git --version
    git version 1.8.1.3
            
    
  • Configure your global username using the following command:
    git config --global user.name "FIRST_NAME LAST_NAME"
            
    
  • Configure your global email address using the following command:
    git config --global user.email "<a href="mailto:MY_NAME@example.com">MY_NAME@example.com</a>"
    Git uses the global email address for all your commits. Also, you can set this value per repository (you'll learn more about this later).

Step 2 - (Optional) Install the git-credential-osxkeychain helper

Bitbucket supports pushing and pulling over HTTP to your remote Git repositories on Bitbucket. Every time you interact with the remote repository, you must supply a username/password combination. Instead of supplying the combination with every HTTP call, you can store these credentials in your OSX keychain provided you have the git-credential-osxkeychain helper added to Git.

The helper asks for your username/password on the first Git operation and then stores the credential. Future operations won't require you to supply a username/password combination. To install the helper, open a terminal window on your local system and do the following:

  • Check if you have the helper installed by determining if you get a usage statement for it.
    $ git credential-osxkeychain
    usage: git credential-osxkeychain <get|store|erase>
            
    

    If you receive a usage statement, skip to Step 5. If the helper is not installed, go to the next step.

  • Download the git-credential-osxkeychain software to your source with curl;
    $ curl -O <a href="//github-media-downloads.s3.amazonaws.com/osx/git-credential-osxkeychain"> //github-media-downloads.s3.amazonaws.com/os...</a>
            
    

    This command downloads the source to a local file called git-credential-osxkeychain. If you don't have curl installed you can use this link.

  • Move the file to the /usr/local/bin directory.
    $ sudo mv git-credential-osxkeychain /usr/local/bin/
            
    
  • Make the file an executable:
    $ chmod u+x /usr/local/bin/git-credential-osxkeychain
            
    
  • Configure git to use the helper.
    $ git config --global credential.helper osxkeychain
    # Set git to use the osxkeychain credential helper
            
    

Step 3 - Install Mercurial

You can use Mercurial from the command line or you can use one of several GUI-based tools such as Sourcetree. These instructions assume you are using Mercurial from the command-line.

  • Make sure you have root access (sudo) on the system where you want to install Mercurial.
  • Download the Mercurial installer from its official website.
    The installer is contained in ZIP file.
  • Double-click the ZIP file to expand it.
  • Double-click the MPKG file to run the installer.
  • Follow the prompts to complete the installation.

  • Open a terminal window.
  • Verify the installation was successful by typing the following at the command line.
    $ hg --version
            
    

    Hg is the chemical symbol for Mercury and hg is the command for mercurial.

  • Determine if you already have a ~/.hgrc file in your environment by entering the following at the command line:
    ls ~/.hgrc
            
    

    If for some reason, you don't have the .hgrc file, you should create one yourself using the touch command:

    touch ~/.hgrc
                    
    

    Icon

    Files that start with a . (period) are hidden files in Mac OSX. By default, the Finder does not show hidden files. There are severaltutorials that show how to show hidden files in finder.

  • Open the Mercurial configuration file ~/.hgrc using your favorite editor.
  • Add a username value to the configuration.

    When you are done, the ~/.hgrc file looks something like this:

    [ui]
    # Name data to appear in commits
    username = Mary Anthony <manthony@atlassian.com>
            
    

    This is default value Mercurial uses, you can also set this for specific repositories (you'll learn more about this later).

  • Save and close the .hgrc file.