Stage
_Git · Reference cheat sheet_
Stage
Git · Reference cheat sheet
📖 Overview
Staging selects which changes enter the next commit via the index (staging area). Use pathspecs and patch mode to craft focused commits instead of dumping the whole working tree.
🧩 Core concepts
- Index / staging area — snapshot between working tree and
HEAD. git add— stage new/modified files;git add -ustages tracked updates/deletes.git restore --staged— unstage while keeping working-tree edits.- Patch staging —
git add -pstages hunks interactively. - Intent to add —
git add -Ntracks a new file as empty for diffing. - Status —
git status/git diff --cachedinspect staged vs unstaged.
💡 Examples
# Stage specific paths
git add README.md src/app.ts
git add src/
# Stage all tracked modifications + deletes (not untracked)
git add -u
# Stage everything under the repo (respects .gitignore)
git add -A
# Interactive hunks
git add -p src/app.ts
# Unstage
git restore --staged src/app.ts
git restore --staged .
# Review
git status
git diff # unstaged
git diff --cached # staged vs HEAD⚠️ Pitfalls
git add .from a subdirectory only stages under that path — use repo-root awareness.- Staging secrets (
.env) is easy to miss — keep.gitignorecurrent. git add -Acan stage deletions you did not intend — reviewgit statusfirst.- Partial staging can leave a file both staged and unstaged with different hunks.