The Staging Area
The staging area (also called the index) is where you prepare changes before committing them. It sits between your working directory (your actual files) and the repository history.
Staging lets you carefully choose exactly which changes go into the next commit, even if you've modified many files. This gives you fine-grained control over your project's history.
git add <file>
git statusWorking directory vs staging vs repository
The working directory holds your edited files. The staging area holds changes you've marked to be committed. The repository holds the permanent, committed history.
Why stage changes?
Staging lets you split unrelated changes into separate, focused commits, rather than committing everything at once, which keeps history clean and easy to understand.
git statusChanges not staged for commit:
modified: index.htmlShows that index.html has been modified but not yet staged.
git add index.html
git statusChanges to be committed:
modified: index.htmlStaging the file moves it from 'not staged' to 'to be committed'.
Key points
- The staging area sits between your files and commit history.
- git add moves changes into the staging area.
- Staging lets you build focused, logical commits.
- git status shows what is staged and what is not.
