The Three States of Git
What you'll learn: You'll understand the three distinct states a file can occupy in Git's workflow and how they govern version control operations.
Core Concept
Git manages files through three logical states that form a pipeline from editing to permanent storage:
- Working Directory — where you actively edit files
- Staging Area (also called "Index") — where you prepare changes for commit
- Repository (committed state) — where Git permanently stores snapshots
Understanding the Pipeline
Think of Git like preparing a group photo album:
- Working Directory is your desk where you arrange and edit photos
- Staging Area is the selection tray where you place photos you've decided to include in the album
- Repository is the bound album itself — once photos are glued in, they're permanently recorded
When you modify a file in your working directory, Git notices it's changed but doesn't track it yet. To prepare that change for permanent storage, you move it to the staging area. This two-step process lets you carefully curate exactly which changes should be grouped together in a single commit. Finally, committing moves staged changes into the repository as a permanent snapshot.
Why Three States?
This design gives you fine-grained control. You might edit five files but only want to commit changes to three of them as one logical unit. The staging area lets you be selective, while keeping unfinished work safely in your working directory.
Key Takeaway: Git's three states—working directory, staging area, and repository—create a controlled pipeline that lets you decide exactly what changes to commit and when, separating active editing from permanent version history.