Git Working Directory, Staging Area, and Repository
This chapter dives deep into Git's three core concepts: Working Directory, Staging Area, and Repository. Understanding these three areas is key to mastering Git.
Overview of the Three Areas
Working Directory
Definition and Characteristics
The Working Directory is where you actually do your work. It contains all project files and folders (except the .git directory).
Characteristics:
- 📁 Contains actual project files
- ✏️ Freely edit, create, delete files
- 👀 Git monitors changes but doesn't auto-save
- 🔄 Can restore to any historical version at any time
Working Directory Example
Output:
Working Directory File States
Files in the working directory can be in the following states:
- Untracked: Newly created files
- Modified: Tracked files that have been changed
- Deleted: Tracked files that have been removed
Output:
Staging Area (Index)
Definition and Characteristics
The Staging Area (also known as Index) is a buffer between the working directory and the repository, used to prepare content for the next commit.
Characteristics:
- 🎯 Precise control over commit content
- 📦 Can stage partial file changes
- 🔄 Can modify staged content multiple times
- 💾 Stored in
.git/indexfile
Staging Area Operations
1. Add Files to Staging Area
2. View Staging Area Content
3. Remove Files from Staging Area
4. Partial Staging
Git allows you to stage only parts of a file's changes: