The three areas of git
Working folder, staging area, repository. Learn this map and git stops being confusing.
Files move in one direction: your folder (working directory) → the checklist (staging) → the photograph (commit).
01The map that explains every command
Every file in your project is always sitting in one of three places, and nearly every confusion in git comes from forgetting which one a file is in right now. The three areas have technical names, but they are simpler than they sound.
The working directory is your folder — the real files you see and edit. Nothing git-related happens there; you just work. The staging area (git also calls it the index) is the checklist for the next photograph: the list of changes that the next commit will include. The repository is the album itself — the permanent, unchangeable record of every photograph you have taken.
- —working directory — the files, on your disk, right now
- —staging area — what the next photograph will include
- —repository — the permanent album of photographs
git add moves files from your folder onto the checklist. git commit photographs the checklist into the album. That is the whole pipeline — every command you will ever learn is either a move between these areas or a question about them.
02Why the middle step exists
The staging area feels like bureaucracy the first time you meet it — why photograph everything when you could just photograph what changed? Here is the reason. Suppose you fixed a bug in one file, and separately started a messy experiment in another file. Both changes are in your folder right now. Without staging, your next save would glue them together into one photograph: fix bug plus half an experiment, indistinguishable forever.
With staging, you choose. You stage the bug fix, commit it as one clean photograph titled fix the login bug, and leave the experiment sitting in your folder, waiting for its own photograph when it grows up. Small, honest photographs are the entire point — they are what makes history readable months later.
Think of a group photograph. The working directory is everyone standing in the room. The staging area is the group you picked to stand in the frame. The commit is the picture being taken. The people left out of the frame are not deleted — they are simply not in this photo.
03Watching the pipeline run
Trace one file's journey. You create it — it exists in the working directory only; git calls it untracked, because no photograph has ever included it. You stage it with git add — it is now on the checklist, and status reports it as new file. You commit — the photograph is taken, the file is in the album, and the checklist is empty again, ready for the next idea.
# file lives in your folder
echo "todo: learn git" > todo.txt
# put it on the photo checklist
git add todo.txt
# take the photo
git commit -m "add my first todo"git status labels every file by where it sits: untracked means working-directory-only, staged means on the checklist, modified means it drifted from the last photograph. Read status, and you always know which area you are standing in.
Practice
The folder below is already a git repository (we ran git init for you). Make something for git to watch.
01.Create any file in the working directory.
hint: Try: echo "hello" > anything.txt
02.Run git status and look at what it says about your new file.
hint: Type: git status