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
fiIn 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
git diff Command: Detect Changes in CIgit diff shows changes between commits or the working tree. Reference for --name-only, --stat, and --exit-cod…
git clean Command: Remove Untracked Files in CIgit clean deletes untracked files. Reference for -f, -d, and -x (git clean -fdx) to fully reset a working tre…
git stash Command: Shelve Changes in CIgit stash saves uncommitted changes aside. Reference for push, pop, and --include-untracked to clean the tree…
git ls-files Command: List Tracked Files in CIgit ls-files lists files in the index. Reference for listing tracked, ignored, or modified files to drive lin…