Skip to content

/codes/git/git-exit-codes

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

CodeMeaningExamples
0Success / truecommit succeeded; git diff --quiet with no changes
1Failure or falsegit diff --exit-code with changes; rejected push; merge-base --is-ancestor not an ancestor
128Fatal error (message starts with fatal:)not a git repository; unknown revision; refusing to merge unrelated histories
129Usage errorunknown option; before Git 2.56 also -h

See them

bash
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

bash
if ! git diff --quiet; then
  echo "working tree has uncommitted changes" >&2
  exit 1
fi

Sources