The three areas of Git
Working directory, staging area and repository: where a change lives at each step, and how to read git status and git diff as a map of those three places.
The three areas of Git
The player loads from youtube-nocookie.com when you press play. Nothing reaches YouTube before that.
Not started
What you'll learn
- A change moves through three places: the working directory where you edit, the staging area where you assemble the next commit, and the repository where commits are stored.
- git add copies the current state of a file into the staging area. It does not record anything permanently.
- git commit turns exactly what is staged into a new commit, and ignores edits you have not staged.
- A file can be both staged and modified: edits after git add are not in the staged version.
- git diff compares working directory to staging area, and git diff --staged compares staging area to the last commit.
Why there is a middle step
If you have used a save button, you might expect version control to work like this: edit, then record. Git adds a step between them, and beginners often find it irritating until they see the reason.
Imagine you spent an afternoon on tinynotes. You fixed a bug in how lines are printed and you also started a half-finished new command. Those are two different pieces of work. If recording a version meant “snapshot every file as it is now”, your history would have one lump called “stuff”. The middle step lets you choose which edits belong in this snapshot and leave the rest for later.
The three places
Think of packing for a trip. Clothes spread over your bedroom are everything you could take. The clothes laid on the bed are the ones you have decided on. The suitcase, once zipped, is the finished thing. Git has the same three spaces.
- Working directory (also called the working tree): the actual files in your project folder. You edit them with your usual tools. Git doesn’t care what you do here until you ask.
- Staging area (also called the index): a list Git keeps of exactly what will go into the next commit. You add to it with
git add. - Repository: the history stored in the hidden
.gitfolder.git committakes what is in the staging area and writes it there as a new commit.
Files move one way in the everyday flow: working directory, then git add into the staging area, then git commit into the repository.
Watching one file move
Here is tinynotes with a single file, notes.py, brand new in a fresh repository. I ran every command below.
$ git status
On branch main
No commits yet
Untracked files:
(use "git add <file>..." to include in what will be committed)
notes.py
notes.py exists only in the working directory. Git sees it and calls it untracked, meaning it isn’t in the staging area or any commit. Now stage it:
$ git add notes.py
$ git status -s
A notes.py
The short format has two columns. The left one is the staging area compared with the last commit, and the right one is the working directory compared with the staging area. A means added to the staging area, with nothing different in the working directory. Commit it:
$ git commit -m "Add notes.py with add and show"
[main (root-commit) 441e365] Add notes.py with add and show
1 file changed, 17 insertions(+)
create mode 100644 notes.py
Your hash will differ. The file is now in all three places, identical in each, and git status is clean.
Staged and modified at the same time
This is the case that explains the design. I added a docstring line at the top of notes.py, staged it, then added another line at the bottom without staging that second edit:
$ git status -s
MM notes.py
M in both columns. The staged version has the docstring, and the working file has the docstring plus the extra line. Git keeps these as two different versions and the two forms of git diff show them apart:
$ git diff
@@ -16,3 +16,4 @@ if __name__ == "__main__":
show()
+# more
$ git diff --staged
@@ -1,3 +1,4 @@
+"""tiny notes"""
import sys
Plain git diff shows what you changed since the last git add, which is the unstaged work. git diff --staged shows what is queued for the next commit. I trimmed the headers to save space. Commit now and only the docstring goes in. The # more line stays behind as an unstaged change, and git status still reports the file as modified afterwards.
That is the whole point of the staging area. You pick what is in the next snapshot, and git diff --staged lets you review it before you commit.
Two things that trip people up
git add copies a moment in time. It stages the file as it is right now. Edit again and you must add again, or the new edit won’t be in the commit.
git commit -a skips new files. The -a flag stages every change to files Git already tracks before committing, which saves typing. I ran git commit -a with an untracked README.md present and it reported “nothing added to commit but untracked files present”. New files always need an explicit git add.
To take something out of the staging area without losing your edit, use git restore --staged <file>. The undoing lesson covers it properly.
What the video covers
The embed plays only the “Git Workflow Overview” chapter of Traversy Media’s “Git & GitHub Crash Course 2025”, from 7:36 to 11:25, about four minutes of a 49-minute video published in January 2025. The chapter title comes from the creator’s own timestamp list. I couldn’t read a transcript, so I can’t quote what it says, but a workflow overview this early in a beginner crash course is where the working directory, staging area and repository are introduced before the commands. The rest of the video continues into git init, remotes and GitHub, which later lessons cover. The channel is English-language, judged from the title and description. ByteByteGo’s four-minute overview and LearnThatStack’s staging-area chapter are linked as second views.
Where this fits
You can now read git status. Next, do it for real from an empty folder: your first repository and commit.
Check yourself
You edit a file, run git add on it, then edit it again, and commit. Which edit is in the commit?
Only the first. The commit holds what was staged at commit time, so the second edit stays in your working directory as an unstaged change.
What does git status show as MM next to a file name in short format?
The file has staged changes and also further unstaged changes on top of them.
Does git commit -a commit a brand-new file you have never added?
No. The -a flag only stages changes to files Git already tracks. New files must be added explicitly.
Go deeper
Notes
Notes are saved to your account.
Everything else on this page works without one — progress and bookmarks keep themselves in this browser and come with you when you sign in. Notes are the one thing worth not trusting to a browser you might clear.
Your notes could not be loaded.