Git exit codes: 0, 1, 128 and 129
verified onenvironmentlocal · windows 10.0.26200 arm64 · GNU bash 5.3.15 (Git Bash) · git version 2.55.0.windows.5updated 2026-10-20
- tool
- Git
- versions
- Git 2.x
- os
- linux, macos, windows
Git uses a small set of exit codes: 0 for success, 1 for a normal "no" or failure (a diff with changes, a failed push, merge-base --is-ancestor false), 128 when it dies with fatal:, and 129 for invalid usage or unknown options.
Exit code table
| Code | Meaning | Examples |
|---|---|---|
| 0 | Success / true | commit succeeded; git diff --quiet with no changes |
| 1 | Failure or false | git diff --exit-code with changes; rejected push; merge-base --is-ancestor not an ancestor |
| 128 | Fatal error (message starts with fatal:) | not a git repository; unknown revision; refusing to merge unrelated histories |
| 129 | Usage error | unknown option; before Git 2.56 also -h |
See them
git init -q -b main repo && cd repo
echo a > f && git add f && git commit -qm init
git diff --quiet; echo "no changes -> $?"
echo b >> f
git diff --quiet; echo "unstaged changes -> $?"
git rev-parse --verify no-such-branch >/dev/null 2>&1; echo "unknown revision -> $?"
git log --no-such-option >/dev/null 2>&1; echo "unknown option -> $?"
git merge-base --is-ancestor HEAD HEAD; echo "is-ancestor (true) -> $?"Output
no changes -> 0 unstaged changes -> 1 unknown revision -> 128 unknown option -> 128 is-ancestor (true) -> 0
Use them in scripts
if ! git diff --quiet; then
echo "working tree has uncommitted changes" >&2
exit 1
fiSources
Related pages
errors · gitfatal: not a git repository (or any of the parent directories): .gitGit prints not a git repository when the current folder and none of its parents contain a .git directory. cd into the repository, run git init, or set GIT_DIR.changes · gitGit 2.55 to 2.56: what changedGit 2.56 makes -h and --help exit with 0 instead of 129, adds git add --resolved, git branch --delete-merged and git refs subcommands, and flags push typos.codes · bashBash exit codes: 0, 1, 2, 126, 127, 128+n and 255What bash exit codes mean: 0 success, 1 general error, 2 misuse of builtins, 126 not executable, 127 not found, 128+n killed by signal n, and how to read $?.