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:
sudo apt update
sudo apt install -y gitOn 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.
| Message | Where you see it | Go to |
|---|---|---|
bash: git: command not found | bash on a Linux server or in a container | Install Git |
-bash: git: command not found | bash as login shell over SSH | Install Git |
Command 'git' not found, but can be installed with: | Ubuntu's command-not-found helper | Install Git |
/bin/sh: 1: git: not found | dash (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 found | Docker |
/bin/sh: git: not found | the same on Alpine images (BusyBox) | Docker |
xcode-select: note: No developer tools were found, requesting install. | macOS, first git without the Command Line Tools | macOS |
xcrun: error: invalid active developer path | macOS, usually after an upgrade | macOS |
zsh: command not found: git | zsh, 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 cmd | Windows |
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 URL | Docker |
git: 'lfs' is not a git command. See 'git --help'. | git works; the Git LFS extension is missing | Git LFS |
Install Git
sudo apt update
sudo apt install -y gitsudo dnf install -y gitapk add --no-cache gitsudo pacman -S --needed gitsudo zypper install -y gitThe 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:
git --versiongit 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:
xcode-select --installAfter a macOS upgrade the same tools can break, and git stops with:
xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrunxcode-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):
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:
winget install --id Git.Git -e --source wingetThen 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 foundfrom aRUN git cloneon a Debian or Ubuntu base,/bin/sh: git: not foundon Alpine.ERROR: Cannot find command 'git' - do you have 'git' installed and in your PATH?frompip install git+https://….npm error syscall spawn gitafternpm error code ENOENT, ending inAn unknown git error occurred, when a dependency points at a Git URL (npm 11 wording; older npm printsnpm ERR!).
Install it in the same layer as the package index, so the image stays small:
RUN apt-get update && apt-get install -y --no-install-recommends git ca-certificates \
&& rm -rf /var/lib/apt/lists/*RUN apk add --no-cache gitca-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:
sudo apt install -y git-lfs
git lfs installAlpine 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:
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.