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.
Git manages your project files through three primary zones:
How data and code flow step-by-step
.git/index..git directory)git commit, the contents currently in the Staging Area are permanently recorded as a snapshot commit object..git directory is what gets copied when you clone a repository.Within the Working Directory, files oscillate between two high-level states: Untracked and Tracked. Tracked files can be Unmodified, Modified, or Staged:
+------------- 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) |
+-------------------+Let's see how files transition between states using standard terminal commands:
Other systems (like SVN or Mercurial) often commit directly from the working directory. Why did Git invent the Staging Area?
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.git diff --staged to verify exactly what is about to enter history before finalizing the commit.git commit -m "Add new page", what is the state of the committed file in the working directory?Continue learning with hands-on practice, examples, and exercises in the upcoming topic.
Test your understanding of this lesson with 5 questions. Each question has one correct answer.
Practice in live mentor-led sessions with real projects, mock tests, and verifiable certification at MSK Institute.