QA
Beginner LevelGit & GitHub

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

bash
# 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"
💡File lifecycle moving through Working Directory, Staging Area, and Commit History.
🎯 Interview Key Takeaway

Git workflow moves files from Working Directory to Staging Area (git add) to Commit History (git commit).

#Three Trees#Staging Area#Index#Beginner
Back to all Git & GitHub Questions→

More Git & GitHub Interview Questions

Beginner LevelGit & GitHub

Compare git rebase versus git merge and explain how git bisect finds regressions.

Beginner LevelGit & GitHub

What is the difference between git init and git clone?

Beginner LevelGit & GitHub

How do git add, git commit, git status, and git diff manage everyday file tracking?