What is the staging area (index) in Git?

Git & SDLC Fundamentals Basic Fresher1–2 Yrs Conceptual 1 min read

Quick Answer

The staging area (the “index”) is a middle step between your working directory and a commit. git add puts changes into staging; git commit records what's staged. It lets you craft a commit from a subset of your changes — you can stage part of a file with git add -p.

The staging area is a buffer between what I've changed and what I'm about to commit. git add moves changes into it, and git commit only records what's staged. The reason it's useful is that I can build a commit deliberately — if I've made two unrelated changes I can stage and commit them separately, and git add -p even lets me stage individual hunks within a file. So there are really three states: modified in the working directory, staged in the index, and committed.

  • Three states: modified (in the working dir), staged (in the index), committed (in the repo).
  • Use it to split unrelated changes into separate, focused commits.
  • git status shows staged vs unstaged; git diff shows unstaged, git diff --staged shows staged.
  • git restore --staged file unstages; git restore file discards working changes.