CPCODELAB
Git & GitHub

Staging Changes with git add

6 min read

Moving Changes to the Staging Area

git add tells Git which changes to include in the next commit. You can add individual files, directories, or use patterns.

bash
git add index.html           # stage a single file
git add src/                 # stage an entire directory
git add *.css                # stage all CSS files
git add -A                   # stage ALL changes (new, modified, deleted)
git add -p                   # interactively choose hunks to stage

Interactive Staging with -p

The -p (patch) flag is powerful: Git shows each changed hunk and asks whether to stage it. Type y to stage, n to skip, s to split into smaller hunks. This lets you make two logical commits from a single editing session.

Prefer git add -p over git add -A for meaningful commit history. Staging everything blindly often mixes unrelated changes into one commit.

Ready to test yourself?
Practice Git & GitHub— quiz & coding exercises