Git Add: Stage Selected Changes
Select the next snapshot
The staging area, also called the index, holds the content Git will normally use for the next commit. git add -- notes.txt updates the index entry for that path using the current file content (subject to any configured conversions). -- separates options from paths. Continue in the lab from lesson 1, with notes.txt containing Tea and no commits.
git add -- notes.txtgit status --shortgit diff --cached -- notes.txtStatus is A notes.txt. The staged diff shows a new line +Tea. Even before the first commit, the cached diff can show staged additions against an empty baseline.
Editing after staging
An index entry does not follow subsequent edits automatically. Add a second line after staging, then compare the staged and unstaged changes. A staged change is not yet a commit.
printf 'Rice\n' >> notes.txtgit status --shortgit diff -- notes.txtgit diff --cached -- notes.txtExpected status: AM notes.txt. The unstaged diff adds Rice; the staged diff still adds only Tea. The first column says added, the second says modified.
Stage the updated content deliberately
If both lines belong in the first commit, stage the file again. Prefer an explicit path while learning. Broad selections such as git add . can include unrelated changes, deletions and untracked files within scope. Inspect first; never stage passwords, tokens or private configuration.
git add -- notes.txtgit diff --cached -- notes.txtgit diff -- notes.txtThe staged diff now includes Tea and Rice. The last command prints nothing because the working file matches the index. Practice: explain why adding twice was necessary. Leave the file staged for lesson 3.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Git Add: Stage Selected Changes — knowledge check
Apply the lesson to common beginner repository states.
What does git add -- notes.txt select?
You stage Tea, then append Rice. What is staged?
Which command inspects what is staged?
How do you include the later Rice edit in the staged version?
Why prefer an explicit path over git add . while learning?