git status is your "where am I" in Git. Without it, work becomes
guesswork. Run it before every add and commit, and after switching
branches.
What it shows
Several sections, top to bottom:
- Current branch and its position relative to the remote:
On branch main,Your branch is ahead of 'origin/main' by 2 commits. - Changes to be committed: what is in the index and will go into the next commit (shown in green).
- Changes not staged for commit: modified tracked files that are not yet in the index (shown in red).
- Untracked files: new files that Git is not tracking (shown in red).
Each section suggests the next command: "use git add to stage", "use
git restore to discard".
Short format
The verbose output is useful for beginners. For day-to-day work, -s
(short) is faster to read:
git status -s
# M README.md ← staged: modified
# MM src/api.ts ← staged and then modified again
# M src/index.ts ← modified, not staged
# ?? newfile.txt ← untracked
# A added.ts ← new, staged
# D deleted.ts ← deleted, staged
Two characters: left is the index state, right is the working tree state. Once you know these symbols, you read the output at a glance.
Branch + ahead/behind
git status -sb adds a branch line at the top showing how far you are
from the remote:
## main...origin/main [ahead 2, behind 1]
You have 2 local commits not in origin, and origin has 1 commit you do not have. You need to merge or rebase before pushing.
Pitfalls
- On large repositories
statuscan be slow. If it is lagging, rungit update-index --refreshor enablefeature.manyFilesorcore.fsmonitorin the config. git statusdoes not show the stash. To see what is stashed, rungit stash list.- If a file is in
.gitignore,statusis silent about it. To find out why a file is ignored, rungit check-ignore -v file.