The Working Directory and the Staging Area
Asha has edited two recipes: she fixed a typo in chai.md and started a half-finished rewrite of pancakes.md. She wants to save only the typo fix. Git makes that possible because a change passes through three places before it becomes history, and you choose what moves between them.
The rule
Edit in the working directory, choose in the staging area, keep in history.
- Working directory: the real files in your folder. This is where you edit. Git notices changes here but has not saved them.
- Staging area (also called the index): a waiting room for the next snapshot.
git addcopies a file's current content here. - Repository history: the commits stored in
.git.git committurns whatever is staged into a permanent snapshot.
git add chai.md # working directory -> staging area
git commit -m "Fix typo in chai recipe" # staging area -> historygit status tells you where everything stands:
git status
# Changes to be committed:
# modified: chai.md
# Changes not staged for commit:
# modified: pancakes.md"To be committed" means staged. "Not staged" means changed in the working directory only. Untracked files are ones Git has never recorded.
To see the actual lines, use two forms of git diff:
git diffcompares the working directory with the staging area: what you changed but have not staged.git diff --stagedcompares the staging area with the last commit: what the next commit will contain.
And to move things back:
git restore --staged chai.mdunstages the file, keeping your edits.git restore pancakes.mdthrows away unstaged edits and returns the file to its staged or committed state. This cannot be undone, so use it with care.
The shortcut
Picture three boxes in a row: Working → Staged → Committed. For any command, ask "which box does this move content between?"
Check the boxes
git statusshows bothchai.mdandpancakes.mdas modified and not staged.
The trap is editing a file after git add. The staging area holds the content from the moment you added it, so the newer edits show as "not staged" too. Run git add again to include them.
Drills
Answer fast — trust the rule.
Which command moves pancakes.md from the working directory into the staging area?
What does git diff --staged show?
Asha runs git add chai.md, then edits chai.md again. What does git status show for it?
Asha staged pancakes.md by mistake. Which command unstages it but keeps her edits?
Remember
- Edit in the working directory, choose in the staging area, keep in history.
- Working → Staged → Committed: ask which boxes a command moves between.
git diffshows unstaged changes;git diff --stagedshows what the next commit holds.
