Git Course 0%

The four areas

Beginner Core Git Git CLI ≈ 12 min

What you will learn

  • What each of the four areas contains
  • The four commands that move a change forward, and the three that read without changing
  • Why the staging area exists at all

After this lesson you can

  • I can say, for any command, which area it reads and which it changes
  • I can follow one change from my editor to the remote and back

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

The four areas of Git Four boxes from left to right: Working tree, Staging area and Local repository inside a bracket labelled Your computer, and Remote repository on the right labelled GitLab or GitHub. Arrows show git add moving a change from the working tree to the staging area, git commit moving it to the local repository, git push sending it to the remote, git fetch bringing remote history into the local repository, and git pull bringing it all the way into the working tree. YOUR COMPUTER GITLAB / GITHUB Working tree the files you see and edit README.md ✎ docs/faq.md Staging area what goes into the next commit README.md ✓ Local repository your commits (the .git folder) main Remote repository the shared copy the team uses origin/main git add git commit git push git fetch git pull pull = fetch + merge into your working tree
The four areas and the commands that move a change between them.

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:

Terminal
$ git status
On 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:

Terminal
$ git add docs/faq.md
$ git status
On 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.md

Commit. git commit turns the staging area into a snapshot in the local repository:

Terminal
$ 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(+)
Terminal
$ git status
On 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 clean

The 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:

Terminal
$ git push
To https://gitlab.com/northwind-trails/trailguide.git
   0d9eb38..2f543f1  main -> main
Terminal
$ git status
On branch main
Your branch is up to date with 'origin/main'.

nothing to commit, working tree clean

All 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 --staged shows 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 status after 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 add and the commit has the old version." The staging area holds the content at the time of git add. Stage again.
  • "git diff shows nothing but git status says modified." The change is staged; git diff compares the working tree with the staging area, which now match. Use git 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).

  1. In the playground, add a line to README.md and run git status.
  2. Run git diff (shows the change), then git add README.md, then git diff again (shows nothing) and git diff --staged (shows the change).
  3. Run git commit -m "docs: note for the four areas exercise" and git 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.

Check yourself

1. You saved a file in VS Code. Which area changed?
2. git diff prints nothing, but git status lists the file under "Changes to be committed". Which command shows the change?
3. After git commit, git status says "Your branch is ahead of 'origin/main' by 2 commits". What does this mean?

Key terms

Working tree Staging area Repository (repo) Remote Commit Push origin