Installing Git on Mac
There are several ways to install Git on macOS. We'll cover the most common methods.
Method 1: Xcode Command Line Tools (Recommended)
The easiest way to install Git on Mac:
bash
1# Open Terminal and run:
2xcode-select --installA dialog will appear asking you to install the command line developer tools. Click Install and wait for it to complete.
Verify Installation
bash
1git --version
2# Output: git version 2.39.0 (or similar)Method 2: Homebrew
If you have Homebrew installed, you can install Git with:
bash
1# Install Homebrew first (if not installed)
2/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
3
4# Install Git
5brew install gitVerify Installation
bash
1git --versionMethod 3: Download from Git Website
- Go to git-scm.com/download/mac
- Download the installer
- Run the installer and follow the prompts
Configure Git
After installation, configure your identity:
bash
1# Set your name
2git config --global user.name "Your Name"
3
4# Set your email (use the same email as your GitHub account)
5git config --global user.email "your.email@example.com"Verify Configuration
bash
1git config --list
2# Output:
3# user.name=Your Name
4# user.email=your.email@example.comOptional: Set Default Editor
Set your preferred text editor for Git:
bash
1# For VS Code
2git config --global core.editor "code --wait"
3
4# For Vim
5git config --global core.editor "vim"
6
7# For Nano
8git config --global core.editor "nano"Optional: Set Default Branch Name
Modern convention is to use main instead of master:
bash
1git config --global init.defaultBranch mainVerify Everything Works
Create a test repository to verify Git is working:
bash
1# Create a test directory
2mkdir git-test
3cd git-test
4
5# Initialize a Git repository
6git init
7# Output: Initialized empty Git repository in /path/to/git-test/.git/
8
9# Create a test file
10echo "Hello Git" > test.txt
11
12# Stage and commit
13git add test.txt
14git commit -m "Initial commit"
15# Output: [main (root-commit) abc1234] Initial commit
16
17# Clean up
18cd ..
19rm -rf git-testTroubleshooting
Command Not Found
If git command is not found:
bash
1# Check if it's in /usr/local/bin
2ls /usr/local/bin/git
3
4# Add to PATH if needed
5export PATH="/usr/local/bin:$PATH"Permission Denied
If you get permission errors:
bash
1# Check permissions
2ls -la $(which git)
3
4# Reinstall with Homebrew
5brew reinstall gitSummary
You've successfully installed Git on your Mac! Key takeaways:
- Xcode CLI is the easiest method
- Homebrew keeps Git updated easily
- Configure your name and email
- Test with a sample repository
Next, let's learn how to install Git on Windows!
