Git sees three main states: modified in your working tree, staged in the index, and committed in history.
Typical flow
git status # see modified paths
git add file.txt # stage changes
git commit -m "..." # record snapshot
Why staging exists
You can craft a commit from part of your edits—useful when a bugfix and a refactor happened in the same afternoon.
Self-check
- What does
git add -phelp you do? - How is the staging area different from the last commit?
Interview prep
- What is the difference between the working tree and the staging area (index)?
The working tree is the files you edit on disk. The staging area holds the next snapshot you intend to record—populated with
git add—before you rungit commit.- What does <code>git add</code> actually do?
It stages a snapshot of the path into the index so the next commit records that version—not every edit in your folder until you commit.