2.5 The staging area — mental model
Think of three trays on your desk: working folder, staging area, and Git history.
- Working tree: files you are still editing — unsaved Git state.
- Staging area: files ready for the next commit —
git add. - Commit history: commits already recorded —
git commit.
You can edit five files but stage only two. The commit then contains only those two. That control is the point of staging.
| Command | Effect |
|---|---|
git status |
Show untracked, modified, and staged files |
git add <file> |
Put one file into the staging area |
git add . |
Stage everything new/changed under this folder (dangerous if secrets exist) |
git restore --staged <file> |
Unstage (keep file edits) |
git diff |
Show unstaged edits |
git diff --staged |
Show what the next commit will include |
Why check status first. Blind git add . stages .env, key files and node_modules if you forgot .gitignore.
Ravindra Bagale's Tip
Khup students thambat nahi — thodach git add . aani commit. Secrets history madhe jatat. Nehmi aadhi git status bagha; nantar specific files git add. Bilkul visru naka.
Steps — practise staging carefully
- Change two files in your hello repo (for example
app.pyandREADME.md). - Run
git status— both should be modified. - Run
git add app.pyonly. - Run
git statusagain — one staged, one not. - Commit with a message only about the API change.
- Stage and commit the README separately with its own message.
What you see: two commits in git log, each with a focused message. That habit helps code review later.