The Three Trees: Working Directory, Staging Area & Git Repository0%

The Three Trees: Working Directory, Staging Area & Git Repository

Beginner12 min read•Updated: Jul 11, 2026
Study MaterialsCheatsheet

The Three Trees: Working Directory, Staging Area & Git Repository

The single most important mental model for understanding Git is the Three States (or Three Trees) Architecture. Almost every Git command moves files between these three distinct areas.


1. The Three Sections of a Git Project

Git manages your project files through three primary zones:

Visual Architecture & Process Flow

How data and code flow step-by-step

Flowchart
Step 1
| that you edit in | -----
Step 2
| for next snapshot | -----
Step 3
| history (snapshots) |

1. The Working Directory (Working Tree)

  • This is the physical folder on your computer filesystem where your project files live.
  • When you open files in VS Code, modify CSS, or add images, you are directly editing the Working Directory.
  • Changes here are untracked or modified, but not yet protected by Git's historical snapshot engine.

2. The Staging Area (The Index)

  • The Staging Area (historically called the Index) is a file located at .git/index.
  • It acts as an intermediate scratchpad where you assemble and curate the exact changes you want to include in your next commit.
  • Staging gives you precise control: if you modified 5 files, you can choose to stage only 2 of them to create a focused, logical commit.

3. The Git Repository (.git directory)

  • This is the permanent vault where Git stores the metadata and object database for your project.
  • When you run git commit, the contents currently in the Staging Area are permanently recorded as a snapshot commit object.
  • The .git directory is what gets copied when you clone a repository.

2. File Status Lifecycle

Within the Working Directory, files oscillate between two high-level states: Untracked and Tracked. Tracked files can be Unmodified, Modified, or Staged:

Visual Architecture Blueprint
+------------- Edit the file ------------+
                 |                                        |
                 v                                        |
+-------------------+      git add      +-------------------+    git commit   +-------------------+
|     Untracked     | ----------------> |      Staged       | --------------> |    Unmodified     |
| (Brand new file)  |                   | (Ready to commit) |                 |  (Committed state)|
+-------------------+                   +-------------------+                 +-------------------+
                                                  ^                                     |
                                                  |                                     |
                                                  +--------- git add (re-stage) --------+
                                                  |                                     |
                                                  v                                     |
                                        +-------------------+                           |
                                        |     Modified      | <--- Modify tracked file -+
                                        | (Changed on disk) |
                                        +-------------------+

3. Practical Terminal Walkthrough

Let's see how files transition between states using standard terminal commands:

Bash / Terminal
# 1. Check current status
git status
# Output: Untracked files: new_feature.py
 
# 2. Move file from Working Directory to Staging Area
git add new_feature.py
 
# 3. Check status again
git status
# Output: Changes to be committed: new file: new_feature.py
 
# 4. Move staged snapshot into the permanent Git Repository
git commit -m "feat: implement user authentication flow"
# Output: [main 3a89e12] feat: implement user authentication flow
# 1 file changed, 45 insertions(+)
 
# 5. Check status after commit
git status
# Output: nothing to commit, working tree clean

4. Why Does Git Have a Staging Area?

Other systems (like SVN or Mercurial) often commit directly from the working directory. Why did Git invent the Staging Area?

  • Crafting Atomic Commits: You can group related modifications together. If you fixed a typo in index.html and wrote a new database migration in db.sql, you shouldn't bundle them into one commit. You stage and commit index.html first, then stage and commit db.sql.
  • Reviewing Diffs Before Saving: You can inspect git diff --staged to verify exactly what is about to enter history before finalizing the commit.

Interactive Quiz

Practice Quiz

Question 1
What are the three primary areas in Git's architecture?
Question 2
What Git command moves modified or untracked files into the Staging Area?
Question 3
What is the main benefit of having a Staging Area rather than committing all working tree changes automatically?
Question 4
Where does Git physically store all committed historical snapshots and objects on your machine?
Question 5
After running git commit -m "Add new page", what is the state of the committed file in the working directory?
Next Lesson

Installing Git and Initial Configuration (git config user.name / email)

Continue learning with hands-on practice, examples, and exercises in the upcoming topic.

Practice Quiz

Test your understanding of this lesson with 5 questions. Each question has one correct answer.

PrevNext