The four areas
Beginner Core Git Git CLI
Why this matters
Almost every confusing Git moment is a question about location: "I saved the file, why does Git say nothing changed?", "I committed, why can't my colleague see it?", "I pulled, where did my edits go?". Git keeps your project in four places at once. Once you can picture them, the answers become obvious, and every command in the course becomes "move something from here to there".
The picture
Try it
Click a file to move it between the areas. Every click prints the command that would have done the same thing in a terminal.
The staging demo loads here.
The first three areas live on your computer. Only the fourth involves the network.
One change, start to finish
Watch a single edit to docs/faq.md travel through all four areas. Ana starts one commit ahead of the remote.
Edit. She adds a question to the FAQ and saves. The change is in the working tree only:
$ git statusOn branch main
Your branch is ahead of 'origin/main' by 1 commit.
(use "git push" to publish your local commits)
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: docs/faq.md
no changes added to commit (use "git add" and/or "git commit -a")Stage. git add copies the change into the staging area:
$ git add docs/faq.md
$ git statusOn branch main
Your branch is ahead of 'origin/main' by 1 commit.
(use "git push" to publish your local commits)
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
modified: docs/faq.mdCommit. git commit turns the staging area into a snapshot in the local repository:
$ git commit -m "docs: explain how to add a trail (#27)"[main 2f543f1] docs: explain how to add a trail (#27)
1 file changed, 4 insertions(+)$ git statusOn branch main
Your branch is ahead of 'origin/main' by 2 commits.
(use "git push" to publish your local commits)
nothing to commit, working tree cleanThe working tree is clean (it matches the newest commit), and the branch is now two commits ahead of the remote: two snapshots exist only on Ana's computer.
Push. git push sends those commits to the remote:
$ git pushTo https://gitlab.com/northwind-trails/trailguide.git
0d9eb38..2f543f1 main -> main$ git statusOn branch main
Your branch is up to date with 'origin/main'.
nothing to commit, working tree cleanAll four areas now agree. Ben can fetch the two commits; the pipeline runs; the change is visible on GitLab.
The commands by area
| Command | Reads | Changes |
|---|---|---|
| editing a file | – | working tree |
git status |
all three local areas | nothing |
git diff |
working tree vs staging area | nothing |
git diff --staged |
staging area vs last commit | nothing |
git add |
working tree | staging area |
git commit |
staging area | local repository |
git push |
local repository | remote |
git fetch |
remote | local repository (remote-tracking branches) |
git pull |
remote | local repository and working tree |
git restore |
staging area or last commit | working tree |
git restore --staged |
last commit | staging area |
Three commands are read-only and always safe: status, diff, log. The rest move things, forward or backward.
Why the staging area exists
Beginners often ask why git add is a separate step. Two reasons that matter in practice:
- Choosing. You can commit part of your work: the finished FAQ answer now, the half-written guide later. Small, focused commits are easier to review and to undo.
- Checking.
git diff --stagedshows exactly what the commit will contain, before it exists. Read it, catch the debug line or the typo, fix, stage again.
IDEs hide the staging area behind checkboxes (VS Code's "Staged Changes" list, IntelliJ's ticked files), but it is always there.
Do and don't
Do
- Run
git statusafter each step while learning; watch the change move. - Stage deliberately (
git add <file>) rather than everything (git add .) until the habit of reading the status is solid. - Push when a piece of work is done, and at least at the end of every day.
Don't
- Don't expect a saved file to be "in Git"; saving touches only the working tree.
- Don't expect a commit to be visible to others; only a push reaches the remote.
- Don't pull with uncommitted edits in the working tree unless you know they do not overlap the incoming changes; commit or stash first (lesson 5.7).
Common mistakes
- "I committed but the pipeline did not run." The pipeline watches the remote. Push.
- "I edited the file after
git addand the commit has the old version." The staging area holds the content at the time ofgit add. Stage again. - "
git diffshows nothing butgit statussays modified." The change is staged;git diffcompares the working tree with the staging area, which now match. Usegit diff --staged.
Try it yourself
Goal: move one change through the three local areas and read git status at each step (the remote comes in Lab 2).
- In the playground, add a line to
README.mdand rungit status. - Run
git diff(shows the change), thengit add README.md, thengit diffagain (shows nothing) andgit diff --staged(shows the change). - Run
git commit -m "docs: note for the four areas exercise"andgit status.
Expected result: status shows modified → staged → clean; git diff goes silent after staging while git diff --staged shows the change; the commit prints 1 file changed, 1 insertion(+).
Show solution
After step 1 the change is in the working tree only. After git add it is in both the working tree and the staging area, so git diff (working tree vs staging) is empty while git diff --staged (staging vs last commit) shows it. After the commit all three local areas agree and the status is clean. If your playground has no remote yet, there is no "ahead of origin" line; Lab 2 adds it.