The Three States: Working Directory, Staging, Repository
You'll learn how Git manages file changes through three distinct stages before they become permanent history.
The Three-Stage Workflow
Git doesn't commit your changes immediately. Instead, it uses a three-stage process that gives you precise control over what gets saved and when.
Think of it like preparing a package for shipping:
- Working Directory: Your desk where you're actively working on documents
- Staging Area (Index): The box where you arrange items you've decided to ship
- Repository: The sealed, labeled package that's been officially sent and recorded
How Files Move Through States
Working Directory
This is your project folder containing all files. When you modify a file, Git notices it's been changed but doesn't do anything automatically. These are "unstaged changes."
Staging Area
When you're ready to commit certain changes, you add them to the staging area using git add. This is your preparation zone. You can review what's staged, add more files, or remove items before committing. The staging area lets you craft exactly which changes go into your next commit—maybe you fixed two bugs but want to commit them separately for clarity.
Repository
When you run git commit, everything in the staging area gets permanently saved to your repository's history with a message describing the changes. This snapshot is now part of your project's timeline.
Why Three Stages Matter
This workflow prevents accidental commits and allows you to organize messy work into clean, logical commits. You might change five files while experimenting, but only stage and commit the two that represent a complete feature. The others stay in your working directory until you're ready.
Key Takeaway: Git's three-stage workflow—working directory, staging area, repository—gives you deliberate control over which changes become permanent history, enabling clean, meaningful commits rather than chaotic snapshots.