Git's Four Areas
Git's add, commit, and push commands are not synonyms for "save." They are three distinct copy operations across four areas: the working tree, the index, the local repository, and the remote repository. Tracking which snapshot lives in each area explains why edits, commits, and pushes can disagree.
How Git's four areas work
Picture four desks in a row: the first holds the files you are editing, the second holds the exact pages selected for the next permanent record, the third stores records on your computer, and the fourth stores records on another machine.
Git gives those desks specific names:
- The working tree is the checked-out set of files your editor reads and writes.
- The index, often called the staging area, is a proposed tree for the next commit.
- The local repository stores commit objects and local branch references such as
main. - The remote repository stores its own commit objects and branch refs such as
refs/heads/main. This lesson labels that server-side branchorigin: mainto keep it distinct from localmain.
The index holds a complete candidate snapshot rather than a temporary queue that becomes empty after a commit. git add app.py copies the current content of app.py from the working tree into that candidate snapshot. A later edit updates the working file without rewriting the index.
A commit is also a snapshot, not a bag of changes. Git records the tree represented by the index, gives the new commit the current HEAD as its parent (none for the first commit) and a message, then moves the current branch reference to that commit. Because the index rather than the working tree is the source of the commit, a staged version and a newer unstaged version can coexist.
Finally, git push transfers commit objects that the remote lacks and asks the remote branch reference to advance. It does not upload the current working file or the current index directly.
Git's four areas step by step
The default run uses one file and one branch so every boundary stays visible.
edit app.pywritesprint("one")into the working tree. The index, local repository, and remote repository are still empty.git add app.pycopiesprint("one")into the index. The working file remains in place; nothing has moved out of it.- A second edit changes the working file to
print("two"). The index still holdsprint("one"). The two areas now contain different snapshots of the same path. git commit -m "save staged one"creates C1 from the index, so C1 containsprint("one"). Git then moves localmainto C1. The newer working copy,print("two"), is still uncommitted.git push origin maincopies C1 to the remote repository and moves the remote'smainbranch to C1. Both repositories agree about the branch tip, while the working tree still differs from that committed snapshot.
Step 4 isolates the role of the index. Expecting the commit to contain print("two") skips the staging area; git commit records the staged tree in the index rather than the current contents of the editor.
What each boundary guarantees
The animation places a comparison badge between each pair of areas. Those badges summarize repository state across each boundary.
Between the working tree and index:
- same means the tracked working content matches what is staged.
- unstaged means the working content differs from the staged candidate.
Between the index and local HEAD:
- nothing staged means committing would not produce a new tree.
- staged means the index differs from the tree stored by
HEAD.
Between local main and the remote's main:
- up to date means both references point to the same commit.
- ahead by N means the local branch reaches N commits that the remote branch does not yet reach.
These comparisons describe snapshots and references rather than a fixed flow direction. Real Git can restore a file from the index, reset a reference, fetch remote objects, merge histories, and perform many other transitions. The left-to-right sequence shown here covers the standard edit-add-commit-push path.
Edge cases
The controls allow commands that perform no work. Those no-ops are part of Git's model rather than animation errors.
- Adding a missing
app.pyleaves the index unchanged. - Adding a working file that already matches the index copies the same snapshot again, so no state changes.
- Committing when the index matches
HEADreports that nothing is staged. An unstaged working edit does not change that result. - Pushing before any local commit has nothing to transfer.
- Pushing when local
mainand the remote'smainalready match is a successful no-op: everything is up to date.
Try the Split snapshots scenario, then commit immediately. Next, load Dirty unstaged and commit without adding. The first saves an older staged version; the second creates no commit at all. Together, those two runs isolate what the index controls.
Common mistakes
"git add tells Git which files changed." Git already knows which working files differ. add writes selected content into the index. Re-run it after another edit if that newer content belongs in the next commit.
"A commit saves everything in my project folder." A commit saves the index. Untracked and unstaged content can remain outside it.
"Committing clears the staging area." After a commit, the index normally matches the new HEAD; it is not empty. A comparison says "nothing staged" because the two snapshots are equal.
"Push sends my latest files." Push negotiates and transfers commits, then updates a remote reference. A file that has not reached a local commit cannot reach the remote through push.
"origin/main is the remote itself." It is a local remote-tracking ref updated by fetch and related operations. The server owns a branch such as refs/heads/main; this lesson labels that server-side ref origin: main so you can compare the two tips without conflating them.
A Note on Simplification
This lesson uses one file, one linear branch, synthetic commit IDs such as C1, and an always-available remote. It leaves out the object database's blob/tree details, detached HEAD, merges, rebases, tags, upstream configuration, remote-tracking lag, authentication, hooks, packing, and network failures. The four-area distinction remains useful when those features return, though real Git commands can cross more than one boundary.
Keep exploring
A few lessons that share the same technique or lead into the next idea.
Premium players need paid access. Every Explain doc is free.
Embed this lesson in a blog, docs, or course?
Found a mistake or something unclear?