The git staging area: three places every change passes through

By Christophe Paka · Facts checked on 7 November 2026

You edit two files, run git commit, and only one of them is in the commit. Or you commit, and the edit you made a minute ago is missing. Readers keep asking what Git's middle step is for, and why they cannot just commit.

Three names for one thing make it worse: staging area, index and cache.

The git staging area is the list of changes you chose for the next commit. The figure below shows the three places a change lives, and the command that moves it between each pair. Learn this one picture, and every later command lands on it.

Three boxes in a row: working tree, the files you edit; staging area, stored in .git/index as the next commit; repository, the history in .git. git add and git commit move a change right; git restore, then restore or switch, move it back.
Figure 2.1: Three areas, one trip through the staging area. A change starts in your files, waits in the staging area, and becomes part of a commit when you commit.
Use this diagram on your site

Free to share in your blog post, docs, course or slides, as long as the credit link stays. Paste the code below where the figure should go.

How to read this figure

  1. Start at the working tree. The left box is the working tree: the files and folders you see and edit in your project folder. An edit here is not saved by Git yet. If you throw it away, Git cannot bring it back, because it never stored it. The safe habit: stage and commit work you want to keep.

  2. Follow git add to the staging area. git add copies a change into the middle box, the staging area. Git's own name for it is the index. The figure shows where Git keeps it: .git/index, a file inside the hidden .git folder of your project. It holds the next commit: what you staged, as it was when you staged it.

  3. Follow git commit to the repository. git commit saves what is staged as a commit in the repository, the right box. The repository is your saved history inside the hidden .git folder. Edits you did not stage are not in that commit.

  4. Read the arrows back. The lower arrows go back. The left one, git restore, copies the staged version of a file over your working tree, and your edit is lost. The right one, labelled restore / switch, brings back something already committed: git restore --source for one old file, or git switch to move to another branch.

  5. Read the rule at the foot. Forward: stage, then commit. Backward: restore a file, or switch to another committed state. Run git status and you can place every file in one of the three boxes. The next figure opens the right box.

Key takeaways

  • Run git status and place each file in one of the three areas before you commit.
  • Stage only what belongs together, then commit it with its own note.
  • Stage again after any later edit, or the commit takes the version you staged first.

Worked example: one trip, and the edit that missed the commit

Take a project folder, my-project, whose README.md is already committed. Watch what git status says at each step.

  1. Add a line to README.md and create notes.txt. git status lists README.md under "Changes not staged for commit" and notes.txt under "Untracked files": Git has never been asked to record it.
  2. Run git add README.md. README.md moves to "Changes to be committed".
  3. Run git commit -m "Update README". Git prints the commit ID, 6d1489c, and 1 file changed. notes.txt stays in your folder, still untracked.
  4. Then the failure case. Stage README.md, edit it again, then commit. git status still lists README.md under "Changes not staged for commit".
  5. The commit holds the version you staged. Run git add README.md again and commit to save the rest.

Result: A commit saves exactly what was staged, nothing you edited afterwards. That is the whole job of the staging area: you choose what goes in.

Questions readers ask

What is the staging area for? Why not just commit?

It lets you choose. Fixed a typo and started an idea in the same hour? Stage the typo, commit it with its own note, and keep the idea for later. Each commit then holds one change you can read, review or undo on its own. git commit -am skips the choice for tracked files.

Are the index, the cache and the staging area the same thing?

Yes. Staging area is the everyday name. Git's own name is the index, and some command options use that word. All three name the list of changes you chose for the next commit.

How do I undo git add before I commit?

Run git restore --staged file. It takes the file out of the staging area and leaves your edit in the working tree, so nothing is lost. Plain git restore file is different: it overwrites your edit.

Sources: Pro Git 1.3: What is Git? (git-scm.com); Pro Git: Reset Demystified (git-scm.com).

This figure is from Git Made Crystal Clear, chapter 2.

The chapter builds the idea step by step, with recipes you can follow, a Try it to check yourself, and every source.

Get the book

All diagrams