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.

“The git command requires the command line developer tools.” The dialog macOS shows when git is run before any developer tools exist. It is not an error — it is the installer. Click Install, or run xcode-select --install from the terminal. Either way, Apple’s Git is what you get; see the next item.

git version 2.39.5 (Apple Git-154) — why does it say Apple Git? Because it is Apple’s build, shipped with the command line tools and versioned on Apple’s schedule rather than Git’s. It is a real, working Git. If you need a current upstream release, install one with Homebrew (brew install git) and make sure /opt/homebrew/bin precedes /usr/bin in your PATH; which git tells you which one is winning.

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 first ten minutes with Git

Git is installed. Three things now, in Terminal, and you will have made your first commit before you close this tab.

  1. Tell Git who you are — every commit records this, and it is the one thing the installer cannot guess.

    git config --global user.name "Your Name"
    git config --global user.email "you@example.com"
    git config --global init.defaultBranch main
    git config --global --list
    user.name=Your Name
    user.email=you@example.com
    init.defaultbranch=main
  2. Make a repository and a first commit — a folder, one file, one snapshot.

    mkdir hello && cd hello
    git init
    echo "# Hello" > README.md
    git add README.md
    git commit -m "First commit"
    git log --oneline
    Initialized empty Git repository in …/hello/.git/
    [main (root-commit) 89ee335] First commit
     1 file changed, 1 insertion(+)
     create mode 100644 README.md
    89ee335 First commit

    That seven-character id is a hash of the snapshot. Yours will differ — it includes your name and the time.

  3. Learn what you just did. Day 1 of the 7-Day Git Challenge is What a commit is: Explain why a commit is a snapshot, not a diff, and why every clone is complete. One lesson a day for a week, tracked in My Academy on this device — no account.

    Start Day 1 → What a commit isSee all seven days

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.

Check your understanding

4 questions — each one asks you to predict what Git or GitHub will do, not to recall a flag.

On macOS, Xcode Command Line Tools and Homebrew are both installed and both provide `git`. What decides which one runs?
Show answer

The order of directories in `PATH` — The shell runs the first `git` it finds along `PATH`. `which -a git` lists every match in resolution order, so you can see which one is winning.

Where does Homebrew live on Apple silicon versus Intel Macs?
Show answer

`/opt/homebrew` on Apple silicon, `/usr/local` on Intel — Homebrew chose a new prefix for Apple silicon. `brew shellenv` sets up whichever is right for the machine, which is why the lesson uses it rather than a hardcoded path.

Which statement about Apple's bundled Git is accurate?
Show answer

It lags upstream releases but is complete and sufficient for this curriculum — Apple's Git trails the upstream version but is a full Git. Homebrew is for people who want the newest features, not a requirement.

Why can a case-only rename (`readme.md` → `README.md`) behave oddly on a default macOS volume?
Show answer

The default filesystem is case-insensitive, so the OS treats both names as the same file — APFS is case-insensitive by default on macOS. Git tracks the exact case, but the filesystem reports one file for both spellings, so the rename needs `git mv` in two steps.

Free Git Engineer Cheat Sheet BundleSix printable references plus downloadable toolkit files — commands, recovery, aliases, a CODEOWNERS starter. No email required.