If you see zsh: command not found: git, Git isn't installed yet.

The easiest fix - just try running git:

git --version

If Git isn't installed, macOS will offer to install it for you via Xcode Command Line Tools.

Install Git

Option 1: Xcode Command Line Tools (Recommended)

xcode-select --install

Click "Install" in the dialog. This installs Git along with other developer tools.

After installation:

git --version

Should show something like git version 2.39.0.

Option 2: Homebrew

If you already use Homebrew:

brew install git

This installs a newer version than the Xcode tools provide.

Option 3: Download from git-scm.com

Go to git-scm.com/download/mac and download the installer.

After Installing

Set up your identity

Git needs to know who you are for commits:

git config --global user.name "Your Name"
git config --global user.email "you@example.com"

Verify setup

git config --list

You should see your name and email.

If Git Was Already Installed

Check your PATH

which git

If this returns nothing, Git isn't in your PATH.

For Homebrew on Apple Silicon:

echo 'export PATH="/opt/homebrew/bin:\$PATH"' >> ~/.zshrc
source ~/.zshrc

For Homebrew on Intel:

echo 'export PATH="/usr/local/bin:\$PATH"' >> ~/.zshrc
source ~/.zshrc

Common Git Commands

Once Git is working:

Command What it does
git init Create a new repository
git clone url Download a repository
git status See what's changed
git add . Stage all changes
git commit -m "message" Save changes
git push Upload to remote
git pull Download latest changes

Set Up SSH for GitHub

To push to GitHub without entering your password every time:

Generate an SSH key

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

Press Enter to accept defaults.

Add it to the SSH agent

eval "\$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519

Copy the public key

pbcopy < ~/.ssh/id_ed25519.pub

Add to GitHub

Go to GitHub → Settings → SSH Keys → New SSH Key, paste, and save.

Test the connection

ssh -T git@github.com

You should see "Hi username! You've successfully authenticated."

Multiple Git Versions

If you have both Xcode git and Homebrew git:

which git            # Shows which one is active
/usr/bin/git --version       # Xcode version
/opt/homebrew/bin/git --version  # Homebrew version (Apple Silicon)

The one earlier in your PATH takes priority.

Update Git

Homebrew:

brew upgrade git

Xcode:

softwareupdate --install -a

Or manually reinstall Xcode Command Line Tools.

Common Issues

"xcrun: error: invalid active developer path":

Reinstall command line tools:

xcode-select --install

Git asks for password on every push:

Set up SSH keys (see above) or use a credential helper:

git config --global credential.helper osxkeychain

Keep Learning

Git is essential for any development work. The free course covers Terminal fundamentals that make you more effective.

Check it out at Mac Terminal for Humans.