Git is a version control system and one of the most important tools for computer programmers because it keeps track of code changes. While most programmers choose to work on a PC, there are some instances where a Mac performs better. Fortunately, Git is available on Mac devices, and it is really easy to get started.

If you've used Xcode on a Mac then you probably already have Git installed, but otherwise, there are a few ways to add Git to a Mac computer. Each method requires the use of Terminal, which you should familiarize yourself with before getting started.

Verify and install Git: easiest method

Since Git is already installed on new Mac computers, it is a good idea to run a quick check. The easiest way to do this is by running a command in Terminal. If Git is installed, then you will get a response listing the version currently running on the computer.

  1. Open Terminal through LaunchPad.
  2. Run the command: git --version
  3. A message may appear asking you to install command line developer tools. This message means Git is not installed on the computer. If this window opens, click Install, followed by Agree to install Git and the necessary developer tools.
  4. Run the command line again to confirm that Git is installed.

Install Git using Homebrew

Another way to install Git is using the Homebrew program. If you already have Homebrew added to your Mac, all you need to do is run a command line in Terminal and you can skip to step 6. Otherwise, you must first run a command to install Homebrew.

  1. Open Terminal on your Mac.
  2. Run the command: /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
  3. Enter your Mac's password when prompted.
  4. Press the Return key to begin the installation.
  5. When finished, run the two commands noted at the bottom of the Terminal window to finish installing all the necessary files for Homebrew.
  6. After the installation of Homebrew is complete, run: brew install git

Install Git via MacPorts

You can also install Git via MacPorts on your Mac via Terminal. The process is very similar to the Homebrew method above as you will need to first install MacPorts, but it's a traditional file download rather than a command line. This method is not very useful, because it does require installing command line developer tools before installing MacPorts. Therefore, Git should automatically install with these developer tools.

  1. Open the Terminal application.
  2. Run: xcode-select --install
  3. Select Install and Agree to the terms to begin the installation of command line developer tools. After this finishes, you can run the command: git --version to verify that Git is now installed. Otherwise, you can continue to manually add Git via MacPorts.
  4. Download the appropriate version of MacPorts for your computer.
  5. Launch the MacPorts installation and Continue through the license agreements before selecting Install.
  6. When finished, the installer will close and delete itself.
  7. Go back to Terminal and run: sudo port install git
  8. Enter your Mac's password when prompted.
  9. Confirm the installation by pressing the Y key, followed by Return.
  10. Wait for the installation to complete and exit Terminal when finished.

Using Git on a Mac

One of my favorite uses for Git is copying an entire repository from GitHub. I don't like navigating GitHub pages, so pulling all the files at once is a lifesaver. With Git now on your MacBook, it is very easy to clone a GitHub repository in just a few steps.

  1. Find a GitHub repository that you wish to download and copy its URL by clicking on Code and then the copy logo.
  2. Open the Terminal application on your Mac.
  3. Type git clone and paste the URL copied in step one.
  4. Run the command and wait for Terminal to download the repository.

What to do next with Git?

Git is a free, open source tool that is available across multiple operating systems, including Linux, Windows, and Mac. Now that you have Git on your Mac, there is no need to do anything else. The program will run in the background and should update automatically. Remember, you will have to install Git again if you restore your Mac, or purchase a new one.