Troubleshooting

git: command not found? Install Git on any Linux

Git is not installed. Fix: sudo apt install git (Debian, Ubuntu), apk add git (Alpine), xcode-select --install (macOS), winget install Git.Git (Windows).

Published · Updated ~6 min read
On this page

Short answer: git: command not found means Git is not installed. It is not part of a base server or container image, and one package fixes it:

Debian · Ubuntu
sudo apt update
sudo apt install -y git

On Alpine it is apk add git, on Rocky, AlmaLinux and Fedora sudo dnf install -y git. On a Mac, xcode-select --install; on Windows, winget install --id Git.Git -e --source winget and then a new terminal. git --version confirms it. If Git is installed and the shell still cannot find it, the problem is PATH; the sections below cover that and the other places this error turns up.

Which error do you see?

The Linux lines are what bash, dash, zsh and BusyBox ash print when git is missing; the PowerShell and pip wording comes from their source code.

MessageWhere you see itGo to
bash: git: command not foundbash on a Linux server or in a containerInstall Git
-bash: git: command not foundbash as login shell over SSHInstall Git
Command 'git' not found, but can be installed with:Ubuntu's command-not-found helperInstall Git
/bin/sh: 1: git: not founddash (Debian, Ubuntu) in a Dockerfile RUN line or a cron job; a #!/bin/sh script prints its own name and line instead, as in ./deploy.sh: 3: git: not foundDocker
/bin/sh: git: not foundthe same on Alpine images (BusyBox)Docker
xcode-select: note: No developer tools were found, requesting install.macOS, first git without the Command Line ToolsmacOS
xcrun: error: invalid active developer pathmacOS, usually after an upgrademacOS
zsh: command not found: gitzsh, the macOS default: on a Mac PATH is broken (on Linux, git is missing)macOS
'git' is not recognized as an internal or external command,Windows cmdWindows
The term 'git' is not recognized as a name of a cmdlet, function, script file, or executable program.PowerShell 7 (5.1: "as the name of a cmdlet, function, script file, or operable program")Windows
ERROR: Cannot find command 'git' - do you have 'git' installed and in your PATH?pip installing from a git+https URLDocker
git: 'lfs' is not a git command. See 'git --help'.git works; the Git LFS extension is missingGit LFS

Install Git

Debian · Ubuntu
sudo apt update
sudo apt install -y git
Rocky · Alma · RHEL · Fedora
sudo dnf install -y git
Alpine
apk add --no-cache git
Arch
sudo pacman -S --needed git
openSUSE
sudo zypper install -y git

The package is called git everywhere. On Ubuntu the command-not-found helper says as much: Command 'git' not found, but can be installed with: is followed by the apt line. On Alpine you are usually root, so there is no sudo in front; on a system where sudo itself is missing, that is a separate problem with its own fix: sudo: command not found.

Verify and set your identity

Confirm the install, then set the name and email every commit is stamped with. Without them, git commit either stops with Author identity unknown or commits under a name guessed from your user and host name:

any system
git --version
any system
git config --global user.name "YOUR NAME"
git config --global user.email "YOUR_EMAIL"

git --version prints for example git version 2.39.5 on Debian 12. Cloning over SSH next? The two errors that usually follow are Host key verification failed and Permission denied (publickey).

git on macOS

A Mac has /usr/bin/git from the first boot, but it is a stub that belongs to the Xcode Command Line Tools. Run it before they are installed and macOS opens a dialog offering to install them, while the terminal prints a line starting xcode-select: note: No developer tools were found, requesting install. Click Install, or start it yourself:

macOS
xcode-select --install

After a macOS upgrade the same tools can break, and git stops with:

macOS · error
xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun

xcode-select --install fixes that too. If it reports the tools as already installed, sudo xcode-select --reset points the system back at them.

Homebrew’s Git is newer than Apple’s: brew install git. On Intel Macs it lands in /usr/local/bin, which already comes before /usr/bin. On Apple Silicon it lands in /opt/homebrew/bin and wins over Apple’s only if Homebrew’s shellenv line is in your shell startup file (~/.zprofile or ~/.zshrc):

macOS · Apple Silicon
eval "$(/opt/homebrew/bin/brew shellenv)"

Because /usr/bin/git always exists, zsh: command not found: git on a Mac means PATH has lost /usr/bin altogether, usually through a line in ~/.zshrc that sets PATH without $PATH. which git or git --version after a new terminal shows which Git you are running.

git on Windows: ‘git’ is not recognized

Windows does not include Git. cmd says 'git' is not recognized as an internal or external command, with operable program or batch file. on the next line, and PowerShell prints the “The term ‘git’ is not recognized” line from the table. Install Git for Windows with the winget command that git-scm.com gives, or with the installer from the same site:

PowerShell or cmd
winget install --id Git.Git -e --source winget

Then close and reopen the terminal, and the editor whose built-in terminal you use (VS Code included): a program that was running during the install keeps its old PATH. Still not recognized? The installer’s “Adjusting your PATH environment” page offers Use Git from Git Bash only, which leaves PATH untouched. Run the installer again and keep the recommended Git from the command line and also from 3rd-party software, or add C:\Program Files\Git\cmd to the Path variable yourself (search the Start menu for “environment variables”). In a new window, where.exe git should print C:\Program Files\Git\cmd\git.exe.

In a Dockerfile, CI or pip

The official debian, ubuntu and alpine images have no Git, and neither do the -slim and -alpine variants of node and python. The full node:22 and python:3.13 images are built on buildpack-deps, which includes Git. Where it is missing, it shows up as:

  • /bin/sh: 1: git: not found from a RUN git clone on a Debian or Ubuntu base, /bin/sh: git: not found on Alpine.
  • ERROR: Cannot find command 'git' - do you have 'git' installed and in your PATH? from pip install git+https://….
  • npm error syscall spawn git after npm error code ENOENT, ending in An unknown git error occurred, when a dependency points at a Git URL (npm 11 wording; older npm prints npm ERR!).

Install it in the same layer as the package index, so the image stays small:

Dockerfile · Debian or Ubuntu base
RUN apt-get update && apt-get install -y --no-install-recommends git ca-certificates \
 && rm -rf /var/lib/apt/lists/*
Dockerfile · Alpine base
RUN apk add --no-cache git

ca-certificates matters with --no-install-recommends: without it, an HTTPS clone stops with server certificate verification failed. CAfile: none CRLfile: none (on Debian 13 server verification failed: certificate signer not trusted.). The same option also drops the SSH client, so a clone from a git@ address fails with error: cannot run ssh: No such file or directory; add openssh-client to the line if you clone over SSH. If the image only needs the repository’s files to build, clone outside or in a build stage and COPY them in; the final image then needs no Git at all. In CI, the job’s image is what needs Git: GitHub’s actions/checkout falls back to downloading a tarball through the REST API when Git 2.18 or newer is not on PATH, so the checkout succeeds and a later git step in the same job still fails.

git: ‘lfs’ is not a git command

A different message from a working Git: git lfs, like any git xyz, is a separate program (git-lfs) that Git looks for on PATH. Install it, then run git lfs install once per user to register its filters:

Debian · Ubuntu
sudo apt install -y git-lfs
git lfs install

Alpine has git-lfs in its community repository and Homebrew has it as brew install git-lfs. Git for Windows already includes it.

Installed but still not found

If the package is present but the shell disagrees, it cached an old lookup or PATH is stripped:

bash · zsh
hash -r
command -v git || ls -l /usr/bin/git
echo "$PATH"

hash -r clears the shell’s memory of where commands are, in bash and zsh alike (zsh also calls it rehash). If /usr/bin/git exists but command -v git prints nothing, PATH lacks /usr/bin; a startup file such as ~/.bashrc or ~/.profile overwrote it. Restore it for this shell with export PATH="/usr/local/bin:/usr/bin:/bin:$PATH" and fix the line that sets PATH without $PATH.

Cloning a large repository is I/O-bound, so it benefits from fast storage. Every VMHeaven KVM plan runs on replicated enterprise NVMe storage, which keeps clones and builds quick.

Another tool missing, or a directory to add to PATH for good in bash, zsh and fish? See command not found: the three causes and the fix for every tool.

Frequently asked

Why does macOS ask to install developer tools when I run git?

On a Mac, /usr/bin/git is a stub for the Xcode Command Line Tools. Accept the dialog or run xcode-select --install. After a macOS upgrade, 'xcrun: error: invalid active developer path' has the same fix.

Why is git not recognized on Windows after installing it?

The terminal or editor was open during the install and kept its old PATH, or the installer's 'Use Git from Git Bash only' option was picked. Open a new terminal; if that does not help, rerun the installer with the recommended PATH option or add C:\Program Files\Git\cmd to PATH.

How do I install git in a Docker image?

On a Debian or Ubuntu base: apt-get update && apt-get install -y --no-install-recommends git ca-certificates in one RUN line. On Alpine: apk add --no-cache git. The slim and alpine variants of node and python have no git; the full images include it.

Related articles

All troubleshooting

Host key verification failed, and WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED

Why SSH refuses a changed host key, how to check the new fingerprint is genuine, and the one command that removes the stale entry from known_hosts.

Permission denied (publickey): every reason SSH rejects your key

The SSH connected but your key was refused. The four causes: wrong user, wrong key offered, bad file permissions, or the key was never installed.

make: command not found? Install build tools the right way

make is not installed. Fix: sudo apt install build-essential (Debian, Ubuntu), apk add build-base (Alpine), xcode-select --install (macOS), winget (Windows).

curl: command not found? How to fix it on any Linux distribution

curl is simply not installed. Fix: sudo apt install curl on Debian and Ubuntu, apk add curl on Alpine, dnf install curl on RHEL. Plus sudo, Docker and PATH.

How to rename a Git branch: local, remote, and master to main

Git rename branch: git branch -m old new renames it locally. Then push the new name, delete the old one on the remote, update clones, move master to main.

How to create a new branch in Git: git switch -c, git checkout -b and git push -u

How to create a new branch in Git with git switch -c or checkout -b, from a tag or remote branch, push it with -u, delete it, and install Git on Ubuntu.

Install winget on Windows Server 2025, 2022 and 2019, or use Chocolatey

Install winget on Windows Server 2025, 2022 and 2019 with Repair-WinGetPackageManager, use winget install and upgrade, or install Chocolatey instead.