Skip to content
LatchkeyLatchkey home

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.

Using this in CI

CI checkouts are shallow and detached by default, which changes the answer this command gives you. Commands that read history, branch names, or tags need the checkout configured for it.

.github/workflows/ci.yml
- uses: actions/checkout@v4
  with:
    fetch-depth: 0   # history, tags, and git describe all need this

- run: |
    git rev-parse --is-shallow-repository   # expect false
    git rev-parse --abbrev-ref HEAD          # prints HEAD when detached

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.

Frequently asked questions

git status Command: Check Tree State in CI?
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.
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.

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card