git status
git status is the loop you live in. It tells you what is staged, what is changed, what is untracked, and where HEAD is relative to upstream.
Git — git status
EXAMPLE
# ===== The default =====
git status
# On branch feature/orders
# Your branch is ahead of 'origin/feature/orders' by 1 commit.
# (use "git push" to publish your local commits)
#
# Changes to be committed:
# (use "git restore --staged <file>..." to unstage)
# modified: src/order.ts
#
# Changes not staged for commit:
# (use "git add <file>..." to update what will be committed)
# (use "git restore <file>..." to discard changes in working directory)
# modified: src/total.ts
#
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
# notes.md
# ===== The compact form (the one you'll actually use) =====
git status -sb
## feature/orders...origin/feature/orders [ahead 1]
M src/order.ts # staged modification
M src/total.ts # unstaged modification
?? notes.md # untracked
# Two-column status: first = index, second = working tree.
# A added, M modified, D deleted, R renamed, ?? untracked, !! ignored, U unmerged.
# ===== Filter by path =====
git status -sb src/ # only files under src/
# ===== Find ignored files (debug .gitignore) =====
git status --ignored -sb
git check-ignore -v dist/main.js # which rule excluded this?
# ===== After a merge or rebase with conflicts =====
git status -sb
## main...origin/main
UU src/handlers.ts # both modified, needs resolution
AA src/types.ts # both added
DU src/legacy.ts # deleted by us, modified by them
# UU/AA/DU mean you must resolve before continuing the merge/rebase.
# ===== Aliases that save time =====
git config --global alias.s 'status -sb'
git config --global alias.sx 'status -sb --ignored'
# Then: git s, git sx
# ===== Read it for THREE things =====
# 1. Branch + upstream (the first line)
# 2. What is staged (column 1)
# 3. What is not staged or untracked (column 2 or '??')
# ===== Patterns to internalise =====
# - Run 'git s' every minute. It is your safety net against accidental loss.
# - Before commit: status, diff --staged, then commit
# - Before push: status, log @{u}..HEAD to see what you're about to publish
# - Before pull: status, then fetch + log HEAD..@{u} to preview incoming work
# ===== Pitfalls =====
# - Untracked files do not show in 'git diff' -> use status to notice them
# - Big LFS files staged accidentally; status shows them with size = 1KB pointer
# - Submodule changes look like 'modified:' but require an extra step (cd in, commit there too)
# - 'Your branch is up to date' is a snapshot; you must 'git fetch' first to know it's current
Why it matters
git status is the dashboard you live on. Make it a reflex (git s) and read it for three things every time: branch + upstream, staged, not staged. Most git mistakes are misreadings of status that a 5-second second-look would have caught.
Tip: Tweak the snippet with Try it Yourself », then sit the quiz at the bottom of the page.
Discussion
Loading…