Introduction
To use Git effectively, you only need to understand three concepts:- Working Directory
- Staging Area (Index)
- Repository
Understanding the Repository
After running:.git folder is called the Local Repository.
It stores Git’s database, including:
- Commit history
- Staging Area (Index)
- Branches
- HEAD (latest commit reference)
- Repository configuration
.git. It remains in your project folder (Working Directory).
The Three States of a File
After the first commit, a file can exist in three different states.
Note
Both the Staging Area and the Latest Commit are physically stored inside the Repository (.git).
How These States Evolve
Before git init
After git init
- No commits
- No history
- No staged files
After git add
After the First Commit
Why Do We Need the Staging Area?
Suppose you modified three files.login.py is complete.
You can choose only that file.
login.py becomes part of the commit.
The Staging Area lets you choose exactly what should go into the next commit.
What Does git status Do?
git status compares two things.
Comparison 1
Comparison 2
git status only compares these states. It does not modify or store anything.
What Happens During git add?
Assume the latest commit contains:
What Happens During git commit?
Run:
What Happens During git push?
Complete Git Workflow
Common Git Commands
Key Takeaways
- The Working Directory contains the files you edit.
- The Repository (
.git) stores Git’s complete database. - The Staging Area (Index) is part of the Repository.
- The Latest Commit (HEAD) is also stored inside the Repository.
git addupdates the Staging Area.git commitcreates a new commit from the staged files.git statuscompares the Working Directory, Staging Area, and Latest Commit.git pushuploads your Local Repository to GitHub.
Remember
- Working Directory → Files you edit.
- Staging Area (Index) → Files selected for the next commit.
- Latest Commit (HEAD) → Most recently committed version.
- Repository (
.git) → Git’s database containing the Staging Area, commit history, branches, and other metadata.