Installing Git
Section Objectives
- Install Git on your operating system
- Verify the installation works correctly
- Understand the difference between Git CLI and Git GUI
- Install GitHub CLI for full GitHub management from the terminal
Installation by Operating System
- Windows
- macOS
- Linux
Windows Installation
Recommended Method: Official Git for Windows Installer
- Go to git-scm.com/download/win
- The download starts automatically (64-bit version)
- Run the installer and follow these recommended options:
| Installer Screen | Recommended Choice |
|---|---|
| Components | Keep defaults (Git Bash Here, Git GUI Here) |
| Default editor | VS Code (or your preferred editor) |
| Initial branch name | main |
| PATH environment | Git from command line and 3rd-party software |
| SSH executable | Use bundled OpenSSH |
| HTTPS transport | Use the OpenSSL library |
| Line endings | Checkout Windows-style, commit Unix-style |
| Terminal emulator | Use MinTTY (default) |
Verify the installation:
git --version
# Expected output: git version 2.x.x.windows.x
Alternative: Installation via winget
winget install --id Git.Git -e --source winget
Alternative: Installation via Chocolatey
choco install git
macOS Installation
Recommended Method: Homebrew
# Install Homebrew if not already installed
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
# Install Git
brew install git
Alternative: Xcode Command Line Tools
xcode-select --install
A dialog box will appear asking you to install the tools. Click "Install".
Alternative: Official macOS Installer
Go to git-scm.com/download/mac and follow the instructions.
Verify the installation:
git --version
# Expected output: git version 2.x.x
macOS comes with an older version of Git pre-installed. Always use Homebrew to get the latest version.
Linux Installation
Ubuntu / Debian:
sudo apt update
sudo apt install git
Fedora / RHEL / CentOS:
# Fedora
sudo dnf install git
# RHEL/CentOS 8+
sudo dnf install git
# CentOS 7
sudo yum install git
Arch Linux:
sudo pacman -S git
openSUSE:
sudo zypper install git
From source (latest version):
sudo apt install make libssl-dev libghc-zlib-dev libcurl4-gnutls-dev \
libexpat1-dev gettext unzip
wget https://github.com/git/git/archive/refs/tags/v2.44.0.tar.gz
tar -xvf v2.44.0.tar.gz
cd git-2.44.0
make prefix=/usr/local all
sudo make prefix=/usr/local install
Verify the installation:
git --version
# Expected output: git version 2.x.x
Installing GitHub CLI
GitHub CLI (gh) lets you manage GitHub repositories, pull requests, and issues directly from your terminal.
- Windows
- macOS
- Linux
# Via winget
winget install --id GitHub.cli
# Via Chocolatey
choco install gh
brew install gh
# Ubuntu/Debian
type -p curl >/dev/null || sudo apt install curl -y
curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | \
sudo dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] \
https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null
sudo apt update
sudo apt install gh
# Fedora/RHEL
sudo dnf install 'dnf-command(config-manager)'
sudo dnf config-manager --add-repo https://cli.github.com/packages/rpm/gh-cli.repo
sudo dnf install gh
Authenticate with GitHub:
gh auth login
# Follow the prompts to authenticate via browser or token
Verify:
gh --version
gh auth status
Git GUI Interfaces (Optional)
While the command line is the recommended approach in this course, these tools can help visualize Git history:
| Tool | Platform | Free? | Description |
|---|---|---|---|
| VS Code (built-in) | All | Yes | Basic Git UI in the editor |
| GitLens (VS Code extension) | All | Yes | Advanced Git visualizer in VS Code |
| GitHub Desktop | Win/Mac | Yes | Simple GUI for GitHub workflows |
| Sourcetree | Win/Mac | Yes | Feature-rich GUI by Atlassian |
| GitKraken | All | Partial | Professional GUI (free for public repos) |
| Fork | Win/Mac | Paid | Very fast and clean GUI |
This course focuses on the command line. Understanding Git commands is essential before using a GUI. A GUI can hide what's really happening and make debugging much harder.
Verifying Your Complete Installation
Run these commands in your terminal and check the output:
# Check Git
git --version
# ✅ git version 2.x.x
# Check GitHub CLI
gh --version
# ✅ gh version 2.x.x
# Check Git is accessible everywhere (not just Git Bash on Windows)
# Open PowerShell or cmd.exe (Windows) or regular terminal (Mac/Linux)
git --version
# ✅ Should work from any terminal
Troubleshooting
"git" is not recognized as a command (Windows)
This means Git is not in your PATH. Solutions:
- Reinstall Git and choose "Git from command line and 3rd-party software" when asked about PATH
- Manually add Git to PATH:
- Open System Properties → Environment Variables
- Add
C:\Program Files\Git\cmdto the PATH variable
- Use Git Bash instead of PowerShell (Git Bash is always configured)
Old version of Git on macOS
macOS includes a very old Apple-patched Git. Install via Homebrew and ensure /usr/local/bin comes before /usr/bin in your PATH:
# Add to ~/.zshrc or ~/.bash_profile
export PATH="/usr/local/bin:$PATH"
# Reload config
source ~/.zshrc
# Verify it's the Homebrew version
which git
# /usr/local/bin/git ✅ (not /usr/bin/git ❌)
Permission denied during Linux installation
You need root (sudo) privileges to install packages. If you don't have sudo access, contact your system administrator or compile Git from source in your home directory.
Next Steps
- Initial Configuration — Configure your name, email, and preferences
- Your First Repository — Create your first Git repository