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.
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.
First, verify whether Git is installed on your system:
On Linux/macOS/Git Bash:
which gitOn Windows (PowerShell/CMD):
where gitIf 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:
C:\Program Files\Git\bin\git.exe
C:\Program Files (x86)\Git\bin\git.exeOn macOS:
/usr/bin/git
/usr/local/bin/gitOn Linux:
/usr/bin/git
/usr/local/bin/gitIf you find Git at one of these locations but the command doesn't work, proceed to add it to your PATH.
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:
choco install gitOr using winget:
winget install Git.GitmacOS:
Install Xcode Command Line Tools (includes Git):
xcode-select --installOr using Homebrew:
brew install gitLinux (Debian/Ubuntu):
sudo apt update
sudo apt install gitLinux (Fedora):
sudo dnf install gitLinux (Arch):
sudo pacman -S gitAfter installation, close and reopen your terminal, then verify:
git --versionIf 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:
C:\Program Files\Git\bin
C:\Program Files\Git\cmd7. Click "OK" to save all dialogs
8. Restart your terminal
Method 2: Using PowerShell (Run as Administrator)
# 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)
set PATH=%PATH%;C:\Program Files\Git\binAfter modifying PATH, restart your terminal and verify:
git --versionIf Git is installed but not in your PATH on Linux or macOS:
Check your current PATH:
echo $PATHAdd Git to PATH temporarily (current session):
export PATH=$PATH:/usr/local/binAdd Git to PATH permanently:
For Bash (edit ~/.bashrc or ~/.bash_profile):
echo 'export PATH=$PATH:/usr/local/bin' >> ~/.bashrc
source ~/.bashrcFor Zsh (edit ~/.zshrc):
echo 'export PATH=$PATH:/usr/local/bin' >> ~/.zshrc
source ~/.zshrcIf Git is installed via Homebrew on macOS:
# Homebrew typically installs to /opt/homebrew/bin (Apple Silicon) or /usr/local/bin (Intel)
echo 'export PATH="/opt/homebrew/bin:$PATH"' >> ~/.zshrc
source ~/.zshrcVerify the fix:
git --version
which gitIf you're using WSL and getting this error, Git needs to be installed within your Linux distribution:
Install Git in WSL:
# Ubuntu/Debian
sudo apt update && sudo apt install git
# Fedora
sudo dnf install gitVerify installation:
git --versionOptional: Use Windows Git from WSL
If you want to use your Windows Git installation from WSL (not recommended but possible):
# Add Windows Git to WSL PATH
echo 'export PATH=$PATH:/mnt/c/Program\ Files/Git/bin' >> ~/.bashrc
source ~/.bashrcHowever, 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:
git config --global user.name "Your Name"
git config --global user.email "[email protected]"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:
RUN apk add --no-cache gitFor Debian/Ubuntu-based images:
RUN apt-get update && apt-get install -y git && rm -rf /var/lib/apt/lists/*For Fedora/RHEL-based images:
RUN dnf install -y git && dnf clean allExample complete 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):
# 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 gitNote: Changes made inside a running container are lost when the container stops unless committed to a new image.
After installing or fixing your PATH, verify everything works correctly:
Check Git version:
git --versionExpected output (version number may vary):
git version 2.43.0Check Git location:
# Linux/macOS/Git Bash
which git
# Windows PowerShell
(Get-Command git).SourceTest a Git command:
git statusIf 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):
git config --global user.name "Your Name"
git config --global user.email "[email protected]"Check your configuration:
git config --listIf everything works, Git is now properly installed and configured on your system.
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:
# 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:
# See which git is being used
which git
type git
# See all git installations in PATH
type -a git # bash/zsh
where git # WindowsGit 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:
# GitHub Actions example
- name: Install Git
run: |
apt-get update
apt-get install -y gitShell-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.
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