How to fix git: command not found in Git

GitBEGINNERLOWUpdated Dec 6, 2025· 246 views

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.

Quick fix

Fixes git: command not found

which git
# or
whereis git
# or check if package is installed
dpkg -l git        # Debian/Ubuntu
rpm -qa | grep git # RHEL/CentOS/Fedora
  1. Verify Git is not installed
  2. Install Git on Linux
  3. Install Git on macOS
  4. Install Git on Windows
git — error
which git
# or
whereis git
# or check if package is installed
dpkg -l git # Debian/Ubuntu
rpm -qa | grep git # RHEL/CentOS/Fedora
git: command not found

What this error means

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

Typical symptoms

  • Any git command returns 'git: command not found' or 'command not found: git'
  • Terminal shows 'bash: git: command not found' on Linux/macOS
  • PowerShell shows 'git : The term 'git' is not recognized' on Windows
  • Scripts that use git commands fail unexpectedly
  • IDE or code editor shows Git-related features as unavailable
  • CI/CD pipelines fail at git operations

Common causes

  1. Git is not installed on the system
  2. Git installation directory is not in the PATH environment variable
  3. Terminal session was not restarted after Git installation
  4. Shell configuration file (~/.bashrc, ~/.zshrc) doesn't include Git's path
  5. Git was installed for a different user account
  6. On Windows, Git was installed without 'Add to PATH' option selected
  7. Using a minimal Docker image or container that doesn't include Git
  8. Homebrew or package manager installation incomplete on macOS

How to fix "git: command not found"

1Verify Git is not installed

First, confirm that Git is actually not installed by checking common installation locations:

On Linux:

bash
which git
# or
whereis git
# or check if package is installed
dpkg -l git        # Debian/Ubuntu
rpm -qa | grep git # RHEL/CentOS/Fedora

On macOS:

bash
which git
# or check Homebrew
brew list git
# or check Xcode Command Line Tools
xcode-select -p

On Windows (PowerShell):

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.

2Install Git on Linux

Install Git using your distribution's package manager:

Debian/Ubuntu:

bash
sudo apt update
sudo apt install git

Fedora:

bash
sudo dnf install git

RHEL/CentOS 7:

bash
sudo yum install git

RHEL/CentOS 8+ / Rocky / Alma:

bash
sudo dnf install git

Arch Linux:

bash
sudo pacman -S git

openSUSE:

bash
sudo zypper install git

Alpine (Docker containers):

bash
apk add git

After installation, verify:

bash
git --version
3Install Git on macOS

There are several ways to install Git on macOS:

Option 1: Xcode Command Line Tools (Recommended)

bash
xcode-select --install

A popup will appear asking to install the tools. Click "Install" and wait for completion.

Option 2: Homebrew
If you have Homebrew installed:

bash
brew install git

If you don't have Homebrew:

bash
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
brew install git

Option 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:

bash
git --version

Note: If you just installed Xcode Command Line Tools and still see the error, restart your terminal.

4Install Git on Windows

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)

powershell
winget install --id Git.Git -e --source winget

Option 3: Using Chocolatey

powershell
choco install git

Option 4: Using Scoop

powershell
scoop install git

After installation, close and reopen your terminal, then verify:

powershell
git --version

If Git still isn't found after installation: You may need to manually add it to PATH (see next step).

5Add Git to PATH on Windows

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)

powershell
# 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)

cmd
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

6Add Git to PATH on Linux/macOS

If Git is installed but not in PATH, update your shell configuration:

For Bash (~/.bashrc or ~/.bash_profile):

bash
# 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 ~/.bashrc

For Zsh (~/.zshrc):

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

For macOS with Homebrew:

bash
# 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 ~/.zshrc

Verify the PATH update:

bash
echo $PATH
which git
git --version
7Fix Git in Docker containers

If you're encountering this error in a Docker container, add Git to your Dockerfile:

Alpine-based images:

dockerfile
FROM node:alpine
RUN apk add --no-cache git

Debian/Ubuntu-based images:

dockerfile
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):

dockerfile
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:

yaml
# GitHub Actions
steps:
  - uses: actions/checkout@v4  # This handles git automatically

# GitLab CI
before_script:
  - apt-get update && apt-get install -y git
8Verify installation and configure Git

After installing Git, verify and complete initial setup:

Verify installation:

bash
git --version
# Should output something like: git version 2.43.0

Configure your identity (required for commits):

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

Verify configuration:

bash
git config --list

Optional but recommended settings:

bash
# 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 cache

Now you can use Git commands:

bash
git clone https://github.com/user/repo.git
git status
git add .
git commit -m "Your message"

Advanced notes

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:

bash
# In ~/.bash_profile
if [ -f ~/.bashrc ]; then
    source ~/.bashrc
fi

2. 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:

bash
# 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 git@2.40

# 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 install

Git 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):

bash
# Install to home directory
./configure --prefix=$HOME/git
make
make install
echo 'export PATH="$HOME/git/bin:$PATH"' >> ~/.bashrc

Using 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:

bash
# 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 --version

To use Windows Git as default in WSL (not recommended for performance):

bash
alias git='/mnt/c/Program\ Files/Git/bin/git.exe'

Frequently asked questions

What does "git: command not found" mean?
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".
How do I fix "git: command not found"?
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.
What causes "git: command not found"?
Git is not installed on the system Git installation directory is not in the PATH environment variable Terminal session was not restarted after Git installation
Is the "git: command not found" error serious?
It is a low-severity error — more of a blocker than a risk. The steps above resolve it.

Official resources & further reading