What are the Three Trees in Git (Working Directory, Staging Area / Index, Commit History)?
❓ Interview Prompt: Explain Git's architecture: Working Directory, Staging Area (Index), and Repository Commit History.
Git manages project files across three main architectural areas (often referred to as the 'Three Trees'):
1. Working Directory (Local Files on Disk):
The actual physical files you edit in your code editor. Changes here are untracked or unstaged until added.
2. Staging Area / Index (The Draft Snapshot):
An intermediate binary file ('.git/index') that stores changes staged for the next commit. Allows selecting specific modified files or line hunks to group into logical commits.
3. Repository / Commit History (The Permanently Recorded Graph):
The immutable Object Database ('.git/objects/') containing all committed snapshots. Once committed, changes are given a unique 40-character SHA-1/SHA-256 hash pointer.
Code Implementation Example
# 1. Make edits in Working Directory
echo "console.log('hello');" > app.js
# 2. Move file from Working Directory to Staging Area (Index)
git add app.js
# 3. Snapshot Staging Area into Permanent Commit History
git commit -m "feat: add app entrypoint"Git workflow moves files from Working Directory to Staging Area (git add) to Commit History (git commit).