Skip to content

How to Install Git on macOS: Xcode Tools, Homebrew and Setup

Lesson 6 of 12Beginner8 min readGit Fundamentals · Getting StartedVerified: Commands verified against official Git and Homebrew documentation

macOS makes Git available through Apple’s Xcode Command Line Tools, and many Macs already have it. The main decision is whether that version is enough, or whether you want a current upstream Git from Homebrew — and, if you install both, knowing which one you are actually running.

Open Terminal and run:

Terminal window
git --version

What it doesPrints the version of Git currently on your PATH.

Why we run itMany Macs already have Git via the Xcode Command Line Tools. Checking first tells you whether you need to install anything at all.

Expected resultEither a version string, or a dialog offering to install the command line developer tools — see below.

Three outcomes are possible.

A version prints. Git is installed. Note the number; Apple’s build typically shows an Apple-specific suffix such as git version 2.39.5 (Apple Git-154).

A dialog appears saying the git command requires the command line developer tools. This is macOS offering to install them. Click Install, or cancel and use one of the methods below.

command not found. No Git and no developer tools. Continue to the next step.

Two supported routes. Read both before choosing.

Apple’s developer tools package includes Git along with compilers and other build tooling.

Terminal window
xcode-select --install

A dialog appears; confirm it and wait for the download to finish. Then verify:

Terminal window
git --version

When to choose this: you want the simplest, Apple-supported route, or you need the other developer tools anyway. Many other tools — including Homebrew — require these tools, so installing them is rarely wasted.

The trade-off: Apple’s bundled Git lags upstream, sometimes by a year or more. It is a complete, working Git and everything in this curriculum works with it. Newer Git features simply will not be available.

If you install Homebrew’s Git alongside Apple’s, both exist on disk and PATH order decides which one runs. This is the most common source of “I upgraded Git but the version did not change.”

Terminal window
which git

What it doesPrints the full path of the git executable your shell will actually run.

Why we run itIt resolves the ambiguity directly. git --version tells you what is running; which git tells you where it came from.

Expected resultA path. Apple's is /usr/bin/git. Homebrew's is /opt/homebrew/bin/git on Apple silicon, or /usr/local/bin/git on Intel Macs.

To see every git on your PATH, in the order the shell would try them:

Terminal window
which -a git
/opt/homebrew/bin/git
/usr/bin/git

The first line wins. If Homebrew’s Git is installed but /usr/bin/git appears first, Homebrew’s directory is not early enough on your PATH. Homebrew’s installer normally configures this; if it did not, add it to your shell profile:

Terminal window
echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> ~/.zprofile
eval "$(/opt/homebrew/bin/brew shellenv)"

On Intel Macs substitute /usr/local/bin/brew. brew shellenv prints the correct settings for your installation, so it adapts automatically rather than hardcoding a path.

  1. Set your name.

    Terminal window
    git config --global user.name "Your Name"
  2. Set your email.

    Terminal window
    git config --global user.email "you@example.com"
  3. Confirm both.

    Terminal window
    git config --global --list
Terminal window
git config --global init.defaultBranch main

Older Git versions — including some Apple builds — create master by default and print a hint about it. This setting makes new repositories use main, matching current convention everywhere.

Terminal window
git config --global core.editor "nano"

Included with macOS and easy to leave: Ctrl+O to save, Ctrl+X to exit.

macOS provides an encrypted credential store — the Keychain — and Git integrates with it through the osxkeychain credential helper. Both Apple’s Git and Homebrew’s Git include it.

Terminal window
git config --global credential.helper osxkeychain

After this, the first HTTPS push prompts for credentials once and stores them in the Keychain. Subsequent operations retrieve them automatically.

Check what is configured:

Terminal window
git config --get credential.helper

To remove a stored credential after rotating a token, open Keychain Access, search for the host name, and delete the entry. Or from the terminal:

Terminal window
git credential-osxkeychain erase

Then type host=github.com, press Enter twice.

Rather than HTTPS and tokens, you can authenticate with an SSH key pair:

Terminal window
ssh-keygen -t ed25519 -C "you@example.com"

This writes ~/.ssh/id_ed25519 (private — never share it) and ~/.ssh/id_ed25519.pub (public — safe to upload to a hosting provider). macOS can store the key’s passphrase in the Keychain so you are not prompted repeatedly:

Terminal window
ssh-add --apple-use-keychain ~/.ssh/id_ed25519

SSH key management is a topic in its own right and will be covered properly in a future GitHub Engineering pillar. HTTPS with the Keychain helper is a perfectly good starting point.

Terminal window
git config --list --show-scope --show-origin

On macOS the scopes typically resolve to:

ScopeTypical location
System/etc/gitconfig, or /opt/homebrew/etc/gitconfig for Homebrew’s Git
Global~/.gitconfig
Local.git/config inside the repository

Local overrides global, and global overrides system.

Apple’s Git updates with macOS system updates. There is no separate command. To force a reinstall of the tools:

Terminal window
sudo rm -rf /Library/Developer/CommandLineTools
xcode-select --install

A dialog says the git command requires developer tools. Expected on a Mac without them. Click Install, or run xcode-select --install.

git --version shows an old version after brew install git. A PATH ordering problem. Run which -a git and confirm Homebrew’s directory comes first. See Step 3.

xcode-select: error: command line tools are already installed. They are present. Run git --version to confirm Git works. To reinstall, remove /Library/Developer/CommandLineTools first.

Author identity unknown when committing.

*** Please tell me who you are.
fatal: unable to auto-detect email address

user.name and user.email are unset in an applicable scope. Return to Step 4 and use --global.

brew: command not found. Homebrew is installed but not on your PATH. Run the brew shellenv commands from Step 3.

Credentials prompted on every push. No credential helper is configured. Run git config --global credential.helper osxkeychain.

fatal: detected dubious ownership in repository. Git refuses to operate on a repository owned by a different user — a safety check. If the ownership is legitimate:

Terminal window
git config --global --add safe.directory /path/to/repo

Add specific paths rather than disabling the check.

Case-sensitivity surprises. The default macOS filesystem is case-insensitive but case-preserving. Renaming Readme.md to README.md may not register as a change. Force it explicitly:

Terminal window
git mv --force Readme.md README.md

This matters when collaborating with Linux users, whose filesystems treat those as two distinct files.

Apple’s Git is part of the developer tools and is not separately removable. To remove the whole package:

Terminal window
sudo rm -rf /Library/Developer/CommandLineTools

Note that this removes compilers and other tooling that other software may depend on.

  • macOS offers Git through Xcode Command Line Tools (xcode-select --install) or Homebrew (brew install git).
  • Apple’s Git lags upstream but is complete and sufficient for this curriculum.
  • With both installed, PATH order decides which runs — which -a git shows the resolution.
  • Homebrew lives at /opt/homebrew on Apple silicon and /usr/local on Intel; brew shellenv configures the right one.
  • credential.helper osxkeychain stores credentials in the encrypted macOS Keychain.
  • The default macOS filesystem is case-insensitive, which affects case-only renames.
  1. Run which -a git. If more than one path appears, you have multiple installations — identify which one wins.
  2. Run git --version and note whether the output includes an (Apple Git-…) suffix.
  3. Set your identity with --global, then confirm with git config --global --list.
  4. Create a scratch directory, run git init, and confirm the branch is named main.

Your environment is ready. The next lesson is a full hands-on tutorial: you will build a repository from nothing, make two commits, and understand exactly what each command did.