How to Stage Changes in Git with git add
Short answer
The git add command marks changes to be included in your next commit by adding them to Git's staging area (also called the index). To stage a specific file, run git add <file>. To stage all changes in the project — including new files, modifications, and deletions — run git add --all (or git add -A). To stage only changes to already-tracked files (skipping new untracked files), use git add -u. To interactively choose which lines or hunks within a file to stage, use git add -p, which walks you through each change and lets you decide whether to include it. Once you have staged the changes you want, create the commit with git commit.
Before you can create a commit in Git, you need to tell Git exactly which changes to include. This is done with git add, which moves changes into the staging area (also called the index). Only staged changes are included when you run git commit.
The Git Cheat Sheet
No need to remember all those commands and parameters: get our popular "Git Cheat Sheet" - for free!
Free. We email you a ZIP with our cheat sheets.
Staging Specific Files
To stage one or more specific files, pass their paths to git add:
git add index.html
git add index.html error.html
You can also pass a directory path to stage all changes within it:
git add src/
Staging All Changes
To stage every change in the project at once — new files, modifications, and deletions:
git add --all
The shorthand -A does the same thing:
git add -A
If you want to stage only changes to files Git already tracks (skipping new, untracked files):
git add -u
Staging Individual Lines or Hunks
Sometimes you only want to commit part of your changes in a file. The -p (patch) flag lets you step through each changed section interactively and choose what to stage:
git add -p
Git will show you each hunk one at a time and ask what to do. The most common responses:
| Key | Action |
|---|---|
y |
Stage this hunk |
n |
Skip this hunk |
s |
Split into smaller hunks |
q |
Quit — stop reviewing hunks |
No Command Line Needed
Staging Chunks or Lines in Tower
Using the Tower Git client, you can easily select the exact chunks & lines you want to add to the next commit.