Master the core architecture of Git by understanding the relationship between Working Directory, Staging Area, and Repository! 🚀
In this hands-on tutorial, you’ll learn how files move across Git layers, how commits work, and most importantly — where git restore pulls files from and why.
This lesson builds a strong foundation for mastering Git workflows and avoiding common mistakes.
🎯 What You’ll Learn
👉 Difference between Working Directory, Staging Area, and Repository
👉 How git add and git commit move files across Git layers
👉 How to read git status -s output
👉 How to verify staging using git ls-files
👉 How to validate repository using git log, git show
👉 Understanding D and AD states in Git
👉 How git restore works internally
👉 Why git restore prefers staging over repository
🧪 Hands-On Lab Covered
Creating a file in working directory
Staging a file using git add
Committing file to repository
Validating repository using:
git show --name-only
git log --name-only
git show HEAD:file1.txt
Deleting file from working directory
Understanding D state (deleted in working directory)
Restoring file using git restore
Verifying working directory and staging after restore
💡 Critical Concept (Very Important)
👉 git restore file1.txt restores from Staging Area (Index)
👉 Why NOT repository?
Because Git follows priority:
Staging Area (Index)
Repository (HEAD)
👉 Staging represents the next intended state, so Git prefers it
🔥 Key Insight
👉 Even after commit, staging still holds the file
👉 Deleting a file from working directory does NOT affect staging or repository
👉 Restore uses staging by default, even when repository also has the file
⚡ When Does Restore Use Repository?
👉 Only when file is NOT present in staging
Example:
git restore --source=HEAD file1.txt
🔑 Commands Used
git status -s
git ls-files
git add file1.txt
git commit -m "Adding file1"
git show --name-only
git log --name-only
git show HEAD:file1.txt
git restore file1.txt
🎯 Who This Video Is For
Beginners moving to intermediate Git
Students preparing for interviews
Developers who want deep Git understanding
👍 If you found this helpful
Like 👍 | Share 🔁 | Subscribe 🔔