basics

git add

Stages file changes into the index so they are included in the next commit. Supports whole files, directories, and interactive patch selection.

git add [<options>] <pathspec>...

Common flags

Flag Purpose
-A / --all Stage all changes including deletions across the whole tree
-u / --update Stage modifications and deletions but not new files
-p / --patch Interactively pick hunks to stage
-n / --dry-run Show what would be added without staging
-f / --force Add files that are gitignored

Examples

git add .

Stage all changes in the current directory

git add -p src/app.js

Interactively stage individual hunks from a file

git add -A

Stage additions, modifications, and deletions repo-wide

Gotcha

'git add .' respects the current directory only, while 'git add -A' spans the whole repo; the two are not equivalent in subfolders.

Related commands

← All Git commands · Git cheat sheet · Git rebase vs merge