Skip to content
Latchkey

git status Command: Check Tree State in CI

git status reports which files are staged, modified, or untracked in the current repository.

The human output of git status is friendly but unstable. CI scripts use the porcelain format, which is guaranteed not to change between Git versions, to decide whether the tree is clean.

Common flags

  • --porcelain - stable, script-friendly output (empty when the tree is clean)
  • --porcelain=v2 - richer machine format with extra fields
  • --short / -s - compact human-readable status
  • --untracked-files=no / -uno - ignore untracked files
  • --branch / -b - include branch and tracking info

Example

shell
# Fail if the build left the tree dirty
if [ -n "$(git status --porcelain)" ]; then
  echo "Uncommitted changes detected:" >&2
  git status --short >&2
  exit 1
fi

In CI

Test for cleanliness with [ -n "$(git status --porcelain)" ]: an empty result means nothing changed. Never parse the default status output in scripts, since its wording is not a stable API; --porcelain is the contract Git promises to keep.

Key takeaways

  • git status --porcelain prints nothing when the tree is clean, making clean-tree checks trivial.
  • The porcelain format is version-stable; the default output is not meant for parsing.
  • Use -uno to ignore untracked files when only tracked changes matter.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →