Himanshu SharmaSoftware engineer
Let’s talk

Git and GitHub · Lesson 3 of 30

The three areas of Git: working tree, staging area and repository

Learn the working tree, staging area and repository, how a file moves between them, and how git status shows where every change currently sits.

12 minWhy version controlUpdated 14 November 2026

Awaiting technical review. This lesson is readable but not yet listed in search engines.

By the end of this lessonDescribe the three areas of Git, predict where a change lives after each command, and read git status output to confirm it.

What you can do after this lesson

You will understand the single most important idea in Git, the three areas a change passes through. Once this clicks, add, commit, restore and reset stop being a pile of commands to memorise. We use a few commands here to illustrate; the next lesson walks through them slowly, with you typing along.

Three places, not two

Most people expect two places: the files on disk and the saved history. Git has a third in the middle.

  1. Working tree (also called the working directory). The ordinary files and folders you open in your editor. Changes here are just edits; Git notices them but has recorded nothing.
  2. Staging area (also called the index). A holding area listing exactly what will go into the next commit. Think of packing a parcel: you choose items and put them in the box.
  3. Repository. The permanent history of commits, kept in a hidden folder named .git at the top of your project. Think of the sealed, labelled parcel placed on the shelf.

A change normally travels left to right:

text
working tree  --git add-->  staging area  --git commit-->  repository

and several commands move changes the other way, which later lessons cover.

Why the middle step exists

Why not commit straight from the working tree? Because real work is messy. Imagine you fixed a typo in the menu and, in another file, started a half-finished discount feature. Those are two separate ideas. With a staging area you can stage only the typo fix, commit it with a clear message, and leave the unfinished work for later. The history stays tidy: one commit, one purpose.

If you want a simple workflow, git commit -a stages and commits every change to already tracked files in one step. It is convenient, but it skips the chance to choose.

Tracked and untracked files

Git sorts files into two groups. Tracked files are ones Git already knows from the last commit or from the staging area. Untracked files are new ones Git has seen but has not been told to include. A new file stays untracked until you git add it, which is why a file you created never shows up in history until you do.

Watching a file move

Here is a real session in a practice repository. The prompt symbol is left out; lines starting with $ are commands.

bash
git init
echo "Sourdough, rye and seeded loaf." > menu.txt
git status
text
On branch main

No commits yet

Untracked files:
  (use "git add <file>..." to include in what will be committed)
	menu.txt

nothing added to commit but untracked files present (use "git add" to track)

The file exists in the working tree only. Now stage it and ask again, this time with the short format:

bash
git add menu.txt
git status -s
text
A  menu.txt

The A in the left column means "added to the staging area". Short status prints two columns: the left column describes the staging area compared with the last commit, and the right column describes the working tree compared with the staging area. Commit it:

bash
git commit -m "Add the bakery menu"
git status
text
[main (root-commit) 5bf5647] Add the bakery menu
 1 file changed, 1 insertion(+)
 create mode 100644 menu.txt
On branch main
nothing to commit, working tree clean

Hashes such as 5bf5647 differ on every machine. "Working tree clean" means all three areas agree.

The staging area is a snapshot

This catches nearly everyone once. Suppose you stage a file and then edit it again before committing:

bash
echo "Add a cinnamon bun." >> menu.txt
git add menu.txt
echo "Add a rye roll." >> menu.txt
git status -s
text
MM menu.txt

Two M letters: modified in both columns. The left M is the staged version (with the bun); the right M says the working tree has a further change (the roll) that is not staged. Committing now would record the bun only. To include the roll you must git add menu.txt again. Git stores the content at the moment you ran add, not the filename.

Looking inside .git

The repository lives in .git. Do not edit its contents by hand, but a quick look makes it less mysterious:

bash
ls .git
cat .git/HEAD
text
COMMIT_EDITMSG
config
description
HEAD
hooks
index
info
logs
objects
refs
ref: refs/heads/main

index is the staging area, objects holds your files' content and commits, refs holds branch labels, and HEAD says which branch you are on. Deleting .git deletes the whole history and turns the folder back into ordinary files, so never do that casually.

Common mistakes

  • Assuming save means commit. Saving a file changes only the working tree.
  • Editing after git add and forgetting to stage again. Use git status before every commit to spot a MM.
  • Using git add . blindly. It stages everything, including files you never meant to include. Read the status first.
  • Thinking an untracked file will be committed with -a. git commit -a covers tracked files only.
  • Deleting .git to "reset" things. That destroys the history.

Exercise

  1. Create a new folder, run git init, and create two files, a.txt and b.txt.
  2. Stage only a.txt and run git status -s. What do you expect for each file?
  3. Edit a.txt again and check status once more.
  4. Commit, then check status a final time.
Show one possible answer

After staging only a.txt, short status shows A a.txt and ?? b.txt. After editing a.txt again it shows AM a.txt: added in the staging area and modified in the working tree. After git commit -m "Add a", a.txt has the staged version recorded; the later edit is still unstaged, so status shows M a.txt and ?? b.txt.

Next: Your first repository: init, add and commit.

Key points

  • The working tree holds the files you edit, the staging area (index) holds what the next commit will contain, and the repository holds committed history.
  • git add copies a file's current content into the staging area; git commit turns the staged content into a permanent snapshot.
  • The staging area lets you build a commit from only some of your changes.
  • git status tells you what is untracked, modified, staged or clean.
  • Staging records the file as it was when you ran git add, so later edits need another git add.

Check yourself

1. Where do your edits live immediately after you save a tracked file in your editor?
2. What does git add notes.txt do?
3. You run git add a.txt, then edit a.txt again, then commit. What is in the commit?
4. In short status output, what does the code ?? mean?