Loading lessons...
The Staging Environment
The Staging Environment
The staging area (also called the index) is a middle step between editing your files and saving them.
Why stage first?
Staging lets you decide exactly which changes go into your next commit. You can:
- Stage only some files, and leave others for later.
- Check everything looks right before committing.
- Group small related changes into clean commits.
Stage files
git add file1.js file2.js
Stage all changes:
git add -A
Or stage only modified and new files (not deletions):
git add -u
Unstage a file
If you staged the wrong file, take it back out of the staging area:
git restore --staged file1.js
The file stays changed in your working directory, it is just no longer staged.
See the difference
git statusshows what is staged and what is not.git diffshows unstaged changes.git diff --stagedshows exactly what is ready to commit.
TL;DR
- The staging area is the "prepare for commit" step.
git addstages files.git restore --stagedunstages them.git diff --stagedpreviews your next commit.