LearnThatStack Ace your next interview
Git & Version Control · question
Question 3 of 54

What is the staging area, and why does Git separate it from commits?

beginner
← All Git & Version Control questions
Re-explain
Visual ↓

The staging area, or index, is where you build your next commit. git add copies a file's current content into the index. git commit turns whatever is staged into the new commit.

The separation lets you choose what goes in: the fix, not the debug print. git add -p goes further and lets you pick single hunks of one file.

git add stages the content, not the file, so edits made after it stay out of the commit until you add them again.

git diff            # working files vs staging area
git diff --staged   # staging area vs last commit
Rewriting in plainer words…

This answer doesn't lend itself to a diagram - it reads best . No credits were charged.

Why there's no diagram: “”

The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓

The diagram below the answer is the concept . Jump to it ↓

Tailored explanation · switch back to · ·
What should the new diagram focus on?
Guided practice for Git & Version Control One question at a time. Answer out loud, get graded, see what you missed.
See it - interactive diagram
One file in three places: working, staged, committed
echo 'fix()' >> app.py
git add app.py
echo 'debug()' >> app.py
git diff
git diff --staged
git commit -m 'fix'
Version of app.pywhat each place holds
working filev1
staging areav1
last commitv1
Command touchesplaces it reads or writes
working filestaging arealast commit
Console
1step

Git keeps app.py in three places: your working file, the staging area and the last commit. Right now all three match.

1 / 7

git add copies a file's content as it is at that moment, so later edits stay out of the commit until you add them again.

© LearnThatStack - diagrams may not be republished without permission.

Other questions have diagrams like this too. Sign in to ask for one where it's missing - it's free.

Create a free account
How well did you know this?
AI:

Saved in this browser - sign in to keep your review list.

How should your speech become text?

Listening… your words appear above as you speak - tap Stop when you're done.

Recording · cr - tap Stop & transcribe when you're done.

Transcribing with AI…

Voice:

Keep going - a few more words and AI can grade it.

Interview lens How interviewers actually use this question

Likely follow-ups

  • How do you unstage a file without losing the edits in your working copy? git restore --staged <file> (or git reset <file>) puts the index back to HEAD's version. The working file keeps your changes.
  • What does git commit -a do, and what does it leave out? It stages changes to tracked files, deletions included, then commits. New untracked files still need an explicit git add.
  • You staged part of a file with git add -p. How do you check exactly what will be committed? git diff --staged shows what goes into the commit. Plain git diff shows what stays behind in the working files.
  • What actually happens when you run git commit after staging your changes? Git builds tree objects from the index, writes a commit pointing at that tree and its parent, then moves the current branch to it.
  • What is the index on disk, and how does it make git status fast? A binary file, .git/index, holding each path, its blob hash and cached file stats, so Git can skip re-hashing files that haven't changed.

What you can say

  1. The staging area, also called the index, is where you build your next commit before you make it.
  2. git add copies a file's current content into the index, and git commit turns whatever is staged into the new commit.
  3. Keeping those two steps apart means I choose what goes in, so the fix gets committed and the debug print stays out.
  4. With git add -p I can go further and stage single hunks of one file.
  5. To check, git diff compares my working files to the index, and git diff --staged compares the index to the last commit.
  6. The catch is that git add stages content, not the file, so edits I make after it stay out of the commit until I add them again.

Weak answers to avoid

  • Treats staging as a pointless extra step It sounds like you've never split a commit. Name what it buys: commit the fix without the debug print, or stage single hunks with git add -p.
  • Thinks git add tracks the file, not its content Edits made after git add stay out of the commit until you add again. Say the index holds the content as it was when you ran git add.
  • Mixes up git diff and git diff --staged Plain git diff compares working files to the index, so staged changes drop out of it. git diff --staged shows what the commit will hold.
Interview lens

Likely follow-ups, what you can say, and the weak answers to avoid.

Sign in free to open it Free account - the lens opens as soon as you're back.

Want a quick review of the fundamentals? See the Git & Version Control cheatsheet.

← Back to all Git & Version Control questions
Pro · $10/mo

47 of 54 Git & Version Control answers are in Pro.

Full answers, code samples, and AI explanations that go simpler or deeper. Cancel anytime.

  • Full answers + code
  • AI explanations, simpler or deeper
  • 1,000 AI credits / month
  • Cancel anytime