FresherTechnicalGit
What does git status show and what states can a file be in?
Try answering first
Model answer
git status summarizes the difference between your working tree, the index (staging area) and the last commit, and tells you the current branch and how it relates to its upstream, for example "ahead by 2 commits".
A file can be in these states:
- Untracked: new, not yet known to Git.
- Modified: tracked and changed in the working tree, but not staged.
- Staged ("changes to be committed"): added to the index for the next commit.
- Unmodified: tracked and identical to the last commit, so it is not listed.
A file can be in two states at once. If you stage a change and then edit the file again, it appears both as staged and as modified.
git status -sb
## main...origin/main [ahead 1]
M src/app.ts # modified, not staged
M src/api.ts # staged
?? notes.txt # untracked
In the short format the first column is the index state and the second is the working tree.
Run git status often, especially before committing, to avoid surprises.
Key points
- Compares working tree, index and last commit
- Untracked, modified, staged and unmodified states
- A file can be staged and modified at once
- Also shows branch and ahead or behind counts
Likely follow-ups
- What do the two columns in git status -s mean?
- How do you stop a file from showing as untracked?
Common mistakes
- Assuming a staged file includes edits made after git add
- Ignoring untracked files and forgetting to commit them