The Three Areas of Git
Understanding these three areas is the key to mastering Git.
The Model
┌─────────────────┐ git add ┌─────────────────┐ git commit ┌─────────────────┐
│ Working Dir │ ──────────> │ Staging Area │ ──────────> │ Repository │
│ (your files) │ │ (ready to save) │ │ (saved history) │
└─────────────────┘ └─────────────────┘ └─────────────────┘
1. Working Directory
This is your project folder — the files you see and edit. When you modify a file, the change exists only in the working directory.2. Staging Area (Index)
The staging area is like a shopping cart. You select which changes to include in your next commit.# Add a file to staging
git add filename.txtAdd all changed files
git add .
3. Repository (Committed)
When you commit, Git permanently saves a snapshot of everything in the staging area.git commit -m "Add new feature"
Why a Staging Area?
The staging area lets you make precise commits. For example:
You changed 3 files, but only 2 are ready:
git add file1.txt file2.txt # Stage only the ready files
git commit -m "Update layout" # Commit just those
file3.txt stays in working directory for later
Analogy: Packing a Suitcase
| Git Concept | Packing Analogy |
|---|---|
| Working Directory | Clothes scattered on your bed |
| git add | Choosing which clothes to pack |
| Staging Area | Clothes placed in the suitcase |
| git commit | Zipping the suitcase shut |
| Repository | Your collection of packed suitcases |
Checking Status
git status
This shows you what's in each area:
- Red files = modified in working directory (not staged)
- Green files = in staging area (ready to commit)
Summary
| Command | Action |
|---|---|
| <code>git add file</code> | Move file to staging |
| <code>git add .</code> | Stage all changes |
| <code>git commit -m "msg"</code> | Save staging area as a commit |
| <code>git status</code> | See what's where |