How to fix bash: git: command not found in Git

GitBEGINNERLOWUpdated Dec 6, 2025· 269 views

This error occurs when Git is not installed on your system or the Git executable is not in your shell's PATH environment variable. The fix involves installing Git or configuring your PATH to include the Git binary directory.

Quick fix

Fixes bash: git: command not found

which git
  1. Check if Git is installed
  2. Install Git on your system
  3. Add Git to PATH on Windows
  4. Add Git to PATH on Linux/macOS
git — error
which git
bash: git: command not found

What this error means

The "bash: git: command not found" error indicates that your shell (Bash) cannot locate the `git` executable when you try to run a Git command. This means either Git is not installed on your system, or the directory containing the Git executable is not included in your system's PATH environment variable. When you type a command like `git status` or `git clone`, your shell searches through directories listed in the PATH variable to find an executable with that name. If Git's installation directory isn't in this list, the shell cannot find it and reports "command not found." This error commonly appears in several scenarios: - **Fresh system install**: Git is not included by default in most operating systems and must be installed separately. - **Windows with Git Bash**: Git was installed but the system PATH wasn't updated, or you're using a different terminal that doesn't have Git in its PATH. - **WSL (Windows Subsystem for Linux)**: Git needs to be installed separately within the Linux distribution, as Windows Git is not automatically available. - **macOS without Xcode tools**: Git comes bundled with Xcode Command Line Tools which may not be installed. - **Corrupted installation**: Git was previously installed but the installation became corrupted or the PATH was modified. - **Virtual environments or containers**: Running in an environment where Git wasn't included in the image or setup.

Typical symptoms

  • Any git command returns 'bash: git: command not found'
  • Terminal shows 'git: command not found' or 'command not found: git'
  • Git commands work in one terminal but not another (e.g., Git Bash vs PowerShell)
  • Git commands fail in scripts or CI pipelines
  • 'which git' or 'where git' returns no results
  • Git worked before but stopped working after system changes

Common causes

  1. Git is not installed on the system
  2. Git installation directory is not in the PATH environment variable
  3. Using a terminal/shell that doesn't inherit the PATH where Git is installed
  4. On Windows: Git was installed for one user but being run by another
  5. On WSL: Trying to use Windows Git from Linux subsystem without explicit path
  6. On macOS: Xcode Command Line Tools not installed
  7. Corrupted Git installation that needs to be reinstalled
  8. PATH variable was modified or reset, removing Git's directory
  9. Running in a container or VM where Git wasn't installed

How to fix "bash: git: command not found"

1Check if Git is installed

First, verify whether Git is installed on your system:

On Linux/macOS/Git Bash:

bash
which git

On Windows (PowerShell/CMD):

powershell
where git

If these commands return no output or an error, Git is either not installed or not in your PATH.

Check common installation locations:

On Windows, Git is typically installed in:

bash
C:\Program Files\Git\bin\git.exe
C:\Program Files (x86)\Git\bin\git.exe

On macOS:

bash
/usr/bin/git
/usr/local/bin/git

On Linux:

bash
/usr/bin/git
/usr/local/bin/git

If you find Git at one of these locations but the command doesn't work, proceed to add it to your PATH.

2Install Git on your system

If Git is not installed, install it using the appropriate method for your operating system:

Windows:

Download and run the official installer from https://git-scm.com/download/win

During installation:
- Select "Git from the command line and also from 3rd-party software" to add Git to PATH
- Choose your preferred default editor
- Select "Use Git and optional Unix tools from the Command Prompt" for full PATH integration

Alternatively, using Chocolatey:

powershell
choco install git

Or using winget:

powershell
winget install Git.Git

macOS:

Install Xcode Command Line Tools (includes Git):

bash
xcode-select --install

Or using Homebrew:

bash
brew install git

Linux (Debian/Ubuntu):

bash
sudo apt update
sudo apt install git

Linux (Fedora):

bash
sudo dnf install git

Linux (Arch):

bash
sudo pacman -S git

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

bash
git --version
3Add Git to PATH on Windows

If Git is installed but not in your PATH, add it manually:

Method 1: Using System Properties GUI

1. Press Win + R, type sysdm.cpl, press Enter
2. Click "Advanced" tab
3. Click "Environment Variables"
4. Under "System variables" (or "User variables"), find and select "Path"
5. Click "Edit"
6. Click "New" and add the Git paths:

bash
C:\Program Files\Git\bin
   C:\Program Files\Git\cmd

7. Click "OK" to save all dialogs
8. Restart your terminal

Method 2: Using PowerShell (Run as Administrator)

powershell
# Add Git to system PATH permanently
$gitPath = "C:\Program Files\Git\bin"
$currentPath = [Environment]::GetEnvironmentVariable("Path", "Machine")
if ($currentPath -notlike "*$gitPath*") {
    [Environment]::SetEnvironmentVariable("Path", "$currentPath;$gitPath", "Machine")
}

Method 3: Using Command Prompt (temporary, for current session)

cmd
set PATH=%PATH%;C:\Program Files\Git\bin

After modifying PATH, restart your terminal and verify:

bash
git --version
4Add Git to PATH on Linux/macOS

If Git is installed but not in your PATH on Linux or macOS:

Check your current PATH:

bash
echo $PATH

Add Git to PATH temporarily (current session):

bash
export PATH=$PATH:/usr/local/bin

Add Git to PATH permanently:

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

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

For Zsh (edit ~/.zshrc):

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

If Git is installed via Homebrew on macOS:

bash
# Homebrew typically installs to /opt/homebrew/bin (Apple Silicon) or /usr/local/bin (Intel)
echo 'export PATH="/opt/homebrew/bin:$PATH"' >> ~/.zshrc
source ~/.zshrc

Verify the fix:

bash
git --version
which git
5Fix Git in WSL (Windows Subsystem for Linux)

If you're using WSL and getting this error, Git needs to be installed within your Linux distribution:

Install Git in WSL:

bash
# Ubuntu/Debian
sudo apt update && sudo apt install git

# Fedora
sudo dnf install git

Verify installation:

bash
git --version

Optional: Use Windows Git from WSL

If you want to use your Windows Git installation from WSL (not recommended but possible):

bash
# Add Windows Git to WSL PATH
echo 'export PATH=$PATH:/mnt/c/Program\ Files/Git/bin' >> ~/.bashrc
source ~/.bashrc

However, this approach has limitations:
- Line ending issues (Windows uses CRLF, Linux uses LF)
- Performance is slower accessing Windows filesystem
- Some Git features may not work correctly

Best practice: Install Git natively within WSL for best compatibility.

Configure Git after installation:

bash
git config --global user.name "Your Name"
git config --global user.email "your.email@example.com"
6Fix Git in Docker containers

If you're getting this error inside a Docker container, Git needs to be installed in the container image:

Add Git to your Dockerfile:

For Alpine-based images:

dockerfile
RUN apk add --no-cache git

For Debian/Ubuntu-based images:

dockerfile
RUN apt-get update && apt-get install -y git && rm -rf /var/lib/apt/lists/*

For Fedora/RHEL-based images:

dockerfile
RUN dnf install -y git && dnf clean all

Example complete Dockerfile:

dockerfile
FROM node:18-alpine
RUN apk add --no-cache git
WORKDIR /app
COPY . .
RUN npm install
CMD ["npm", "start"]

For running containers (temporary fix):

bash
# Enter the container
docker exec -it container_name sh

# Install Git (Alpine)
apk add --no-cache git

# Install Git (Debian/Ubuntu)
apt-get update && apt-get install -y git

Note: Changes made inside a running container are lost when the container stops unless committed to a new image.

7Verify installation and basic configuration

After installing or fixing your PATH, verify everything works correctly:

Check Git version:

bash
git --version

Expected output (version number may vary):

bash
git version 2.43.0

Check Git location:

bash
# Linux/macOS/Git Bash
which git

# Windows PowerShell
(Get-Command git).Source

Test a Git command:

bash
git status

If you're not in a Git repository, you'll see "fatal: not a git repository" - that's expected and means Git is working.

Set up your identity (required for commits):

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

Check your configuration:

bash
git config --list

If everything works, Git is now properly installed and configured on your system.

Advanced notes

Understanding the PATH environment variable:

The PATH is an environment variable that tells your shell where to look for executable programs. When you type a command, the shell searches each directory in PATH (in order) until it finds a matching executable.

View your current PATH:

bash
# Linux/macOS
echo $PATH

# Windows PowerShell
$env:PATH

# Windows CMD
echo %PATH%

PATH entries are separated by colons on Linux/macOS and semicolons on Windows.

Multiple Git installations:

Sometimes you may have multiple Git installations (e.g., Git for Windows and Git in WSL). Check which one your shell is using:

bash
# See which git is being used
which git
type git

# See all git installations in PATH
type -a git  # bash/zsh
where git    # Windows

Git installation on CI/CD systems:

Common CI/CD platforms include Git by default:
- GitHub Actions: Pre-installed
- GitLab CI: Pre-installed in most images
- Jenkins: May need to install or configure Git path
- CircleCI: Pre-installed in most images

If Git is missing in CI, add an installation step:

yaml
# GitHub Actions example
- name: Install Git
  run: |
    apt-get update
    apt-get install -y git

Shell-specific PATH configuration:

Different shells read different configuration files:

| Shell | Configuration Files |
|-------|-------------------|
| Bash | ~/.bashrc, ~/.bash_profile, ~/.profile |
| Zsh | ~/.zshrc, ~/.zprofile |
| Fish | ~/.config/fish/config.fish |
| PowerShell | $PROFILE |

Troubleshooting persistent PATH issues:

If PATH changes don't persist:

1. Make sure you're editing the right file for your shell
2. Verify the file is being sourced (add an echo statement to test)
3. Check for PATH overrides in other config files
4. On macOS, check /etc/paths and /etc/paths.d/

Using Git portable version (Windows):

If you can't install Git system-wide, use the portable version:
1. Download PortableGit from https://git-scm.com/download/win
2. Extract to a folder (e.g., C:\PortableGit)
3. Run git-bash.exe from that folder, or add the bin folder to PATH manually

This is useful for shared computers or systems where you don't have admin rights.

Frequently asked questions

What does "bash: git: command not found" mean?
The "bash: git: command not found" error indicates that your shell (Bash) cannot locate the git executable when you try to run a Git command. This means either Git is not installed on your system, or the directory containing the Git executable is not included in your system's PATH environment variable. When you type a command like git status or git clone, your shell searches through directories listed in the PATH variable to find an executable with that name.
How do I fix "bash: git: command not found"?
This error occurs when Git is not installed on your system or the Git executable is not in your shell's PATH environment variable. The fix involves installing Git or configuring your PATH to include the Git binary directory.
What causes "bash: git: command not found"?
Git is not installed on the system Git installation directory is not in the PATH environment variable Using a terminal/shell that doesn't inherit the PATH where Git is installed
Is the "bash: 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