This error occurs when Git is not installed on your system or is not available in your PATH environment variable. The solution involves installing Git or configuring your shell to find the Git executable.
The "git: command not found" error indicates that your shell cannot locate the Git executable when you try to run a Git command. This is one of the most common errors encountered by developers setting up a new development environment. When you type a command like `git status` or `git clone`, your shell searches through directories listed in the PATH environment variable to find an executable named "git". If Git isn't installed, or if its installation directory isn't in your PATH, the shell cannot find it and displays this error. This error typically occurs in the following scenarios: - **Fresh system installation**: Git is not pre-installed on most operating systems - **New terminal session**: After installing Git, you may need to restart your terminal or reload your shell configuration - **PATH misconfiguration**: Git is installed but its directory isn't in the PATH - **Multiple shell environments**: Git may be configured for one shell (like bash) but not another (like zsh) - **Virtual environments or containers**: Running in an environment where Git wasn't included - **Windows-specific**: Git was installed but not added to the system PATH during installation
First, confirm that Git is actually not installed by checking common installation locations:
On Linux:
which git
# or
whereis git
# or check if package is installed
dpkg -l git # Debian/Ubuntu
rpm -qa | grep git # RHEL/CentOS/FedoraOn macOS:
which git
# or check Homebrew
brew list git
# or check Xcode Command Line Tools
xcode-select -pOn Windows (PowerShell):
Get-Command git -ErrorAction SilentlyContinue
# or check common install locations
Test-Path "C:\Program Files\Git\bin\git.exe"
Test-Path "C:\Program Files (x86)\Git\bin\git.exe"If any of these commands find Git, skip to the "Add Git to PATH" step.
Install Git using your distribution's package manager:
Debian/Ubuntu:
sudo apt update
sudo apt install gitFedora:
sudo dnf install gitRHEL/CentOS 7:
sudo yum install gitRHEL/CentOS 8+ / Rocky / Alma:
sudo dnf install gitArch Linux:
sudo pacman -S gitopenSUSE:
sudo zypper install gitAlpine (Docker containers):
apk add gitAfter installation, verify:
git --versionThere are several ways to install Git on macOS:
Option 1: Xcode Command Line Tools (Recommended)
xcode-select --installA popup will appear asking to install the tools. Click "Install" and wait for completion.
Option 2: Homebrew
If you have Homebrew installed:
brew install gitIf you don't have Homebrew:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
brew install gitOption 3: Download from git-scm.com
1. Visit https://git-scm.com/download/mac
2. Download the installer
3. Run the .dmg file and follow the installation wizard
After installation, verify:
git --versionNote: If you just installed Xcode Command Line Tools and still see the error, restart your terminal.
Option 1: Git for Windows (Recommended)
1. Download from https://git-scm.com/download/win
2. Run the installer
3. Important: During installation, select "Git from the command line and also from 3rd-party software" to add Git to PATH
4. Complete the installation wizard
Option 2: Using winget (Windows Package Manager)
winget install --id Git.Git -e --source wingetOption 3: Using Chocolatey
choco install gitOption 4: Using Scoop
scoop install gitAfter installation, close and reopen your terminal, then verify:
git --versionIf Git still isn't found after installation: You may need to manually add it to PATH (see next step).
If Git is installed but not found, add it to your PATH:
Method 1: Using System Properties GUI
1. Press Win + R, type sysdm.cpl, press Enter
2. Go to "Advanced" tab
3. Click "Environment Variables"
4. Under "System variables", find "Path" and click "Edit"
5. Click "New" and add: C:\Program Files\Git\cmd
6. Click "OK" on all dialogs
7. Restart your terminal
Method 2: Using PowerShell (Admin)
# Check current PATH
$env:Path -split ';'
# Add Git to PATH for current session
$env:Path += ";C:\Program Files\Git\cmd"
# Add permanently (requires admin)
[Environment]::SetEnvironmentVariable(
"Path",
$env:Path + ";C:\Program Files\Git\cmd",
[EnvironmentVariableTarget]::Machine
)Method 3: Using Command Prompt (Admin)
setx /M PATH "%PATH%;C:\Program Files\Git\cmd"Common Git installation paths on Windows:
- C:\Program Files\Git\cmd
- C:\Program Files\Git\bin
- C:\Program Files (x86)\Git\cmd
- %USERPROFILE%\AppData\Local\Programs\Git\cmd
If Git is installed but not in PATH, update your shell configuration:
For Bash (~/.bashrc or ~/.bash_profile):
# Find where git is installed
find /usr -name "git" -type f 2>/dev/null
# Add to PATH (example for /usr/local/bin)
echo 'export PATH="/usr/local/bin:$PATH"' >> ~/.bashrc
source ~/.bashrcFor Zsh (~/.zshrc):
echo 'export PATH="/usr/local/bin:$PATH"' >> ~/.zshrc
source ~/.zshrcFor macOS with Homebrew:
# Homebrew on Apple Silicon (M1/M2)
echo 'export PATH="/opt/homebrew/bin:$PATH"' >> ~/.zshrc
# Homebrew on Intel Mac
echo 'export PATH="/usr/local/bin:$PATH"' >> ~/.zshrc
source ~/.zshrcVerify the PATH update:
echo $PATH
which git
git --versionIf you're encountering this error in a Docker container, add Git to your Dockerfile:
Alpine-based images:
FROM node:alpine
RUN apk add --no-cache gitDebian/Ubuntu-based images:
FROM ubuntu:22.04
RUN apt-get update && apt-get install -y git && rm -rf /var/lib/apt/lists/*Multi-stage build (install only in build stage):
FROM node:18 AS builder
RUN apt-get update && apt-get install -y git
# ... build commands that need git ...
FROM node:18-slim
# ... production image without git ...For CI/CD pipelines, most CI images include Git by default, but if not:
# GitHub Actions
steps:
- uses: actions/checkout@v4 # This handles git automatically
# GitLab CI
before_script:
- apt-get update && apt-get install -y gitAfter installing Git, verify and complete initial setup:
Verify installation:
git --version
# Should output something like: git version 2.43.0Configure your identity (required for commits):
git config --global user.name "Your Name"
git config --global user.email "[email protected]"Verify configuration:
git config --listOptional but recommended settings:
# Set default branch name to 'main'
git config --global init.defaultBranch main
# Set default editor (examples)
git config --global core.editor "code --wait" # VS Code
git config --global core.editor "vim" # Vim
git config --global core.editor "nano" # Nano
# Enable colored output
git config --global color.ui auto
# Set credential helper (avoid typing password repeatedly)
# macOS:
git config --global credential.helper osxkeychain
# Windows:
git config --global credential.helper manager-core
# Linux:
git config --global credential.helper cacheNow you can use Git commands:
git clone https://github.com/user/repo.git
git status
git add .
git commit -m "Your message"Troubleshooting persistent PATH issues:
If Git keeps disappearing from PATH after restarting your terminal, check:
1. Multiple shell configuration files: On macOS, both ~/.bash_profile and ~/.bashrc may exist. Login shells read ~/.bash_profile, while non-login shells read ~/.bashrc. Add your PATH modification to both, or source one from the other:
# In ~/.bash_profile
if [ -f ~/.bashrc ]; then
source ~/.bashrc
fi2. Shell-specific issues: If you switched from bash to zsh (macOS Catalina+), your old ~/.bashrc settings don't apply. Migrate settings to ~/.zshrc.
3. System vs User PATH: Some systems have /etc/paths or /etc/paths.d/ that set the system-wide PATH. Check these if user config doesn't work.
Installing specific Git versions:
Sometimes you need a specific Git version:
# Ubuntu PPA for latest Git
sudo add-apt-repository ppa:git-core/ppa
sudo apt update
sudo apt install git
# macOS with Homebrew (specific version)
brew install [email protected]
# From source (any platform)
wget https://github.com/git/git/archive/refs/tags/v2.43.0.tar.gz
tar -xzf v2.43.0.tar.gz
cd git-2.43.0
make prefix=/usr/local all
sudo make prefix=/usr/local installGit in restricted environments:
In corporate or restricted environments where you can't install software:
1. Portable Git (Windows): Download PortableGit from git-scm.com - runs without installation
2. User-space installation (Linux):
# Install to home directory
./configure --prefix=$HOME/git
make
make install
echo 'export PATH="$HOME/git/bin:$PATH"' >> ~/.bashrcUsing Git through different interfaces:
If command-line Git isn't available, consider:
- GitHub Desktop: GUI application with bundled Git
- VS Code: Built-in Git integration (uses its own Git if available)
- GitKraken, Sourcetree: GUI clients with bundled Git
- Web interfaces: GitHub, GitLab web UI for basic operations
WSL (Windows Subsystem for Linux):
Git installed in WSL is separate from Windows Git:
# Install Git in WSL
sudo apt update && sudo apt install git
# Or use Windows Git from WSL (if installed)
/mnt/c/Program\ Files/Git/bin/git.exe --versionTo use Windows Git as default in WSL (not recommended for performance):
alias git='/mnt/c/Program\ Files/Git/bin/git.exe'warning: BOM detected in file, this may cause issues
UTF-8 Byte Order Mark (BOM) detected in file
fatal: Server does not support --shallow-exclude
Server does not support --shallow-exclude
warning: filtering out blobs larger than limit
Git partial clone filtering large blobs warning
fatal: Server does not support --shallow-since
Server does not support --shallow-since in Git
kex_exchange_identification: Connection closed by remote host
Connection closed by remote host when connecting to Git server