# git status Command: Check Tree State in CI

> git status shows working tree and index state. Reference for --porcelain, the stable machine-readable format CI uses to detect uncommitted changes.

Source: https://latchkey.dev/learn/command-reference/git-status-command-reference  
Updated: 2026-06-26

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
```

> `git rev-parse --abbrev-ref HEAD` returns the literal string `HEAD` on a detached checkout rather than a branch name. On GitHub Actions read `github.ref_name` instead; the git command cannot know what it was checked out for.

## FAQ

### 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.

---

Latchkey runs CI/CD that repairs its own failures. Agent entry points: https://latchkey.dev/agent.txt, https://latchkey.dev/openapi.json, https://latchkey.dev/llms.txt
