ILILCode
HomeGitChanges

Staging: choosing what goes into the snapshot

Read the status codes, add files on purpose, and see the difference before you commit.

Lesson 3 of 9 in Git7 min1 exercise

Git does not commit everything you changed. You stage the changes that belong together, then commit them. That extra step is what lets one commit be one coherent idea.

Status, add, and the two diffs
git status --short

#  M notes.txt      modified, not staged
# M  app.js         staged
# ?? draft.md       untracked

git add notes.txt    # stage one file
git add .            # stage everything in this folder

git diff             # working directory vs staging area
git diff --staged    # staging area vs last commit
  • The left column is the staging area, the right column is the working directory.
  • ?? means Git has never seen the file — add it to start tracking it.
  • New files are never staged automatically, even after the first commit.

Exercises

Checked in your browser · hints and solutions included

01

Exercise

Stage everything

You changed three files in the current folder and want all of those changes in the next commit. Stage every change.

terminal