Home·Terminal commands

git add

git

Usage

git add [-A|-u|-p] <pathspec>...

Stages the file as it looks right now; editing it again after add leaves that change out, so you have to add once more.

Common flags

FlagMeaning
-Astage every change in the whole tree, deletions included
-ustage changes to tracked files only, no new files
-pwalk the diff and choose hunk by hunk
-ndry run: list what would be staged
-fstage a file that .gitignore excludes
-Nrecord the path only, so the file shows up in diffs

Examples

git add -A

stages everything, including files you deleted

git add -p src/app.ts

stages part of one file and leaves the rest

git add .

stages everything under the current directory

The confusion is that undo has several shapes — moving where a branch points is not the same as adding a commit that reverses it.

How to read this

  • Square brackets [ ] mark a part you may leave out.
  • An ellipsis … means you can list more than one.
  • Flags are case-sensitive — in some commands -r and -R do different things.

Questions

Q. What does git add do?

Stages the file as it looks right now; editing it again after add leaves that change out, so you have to add once more.

Q. How do I type it?

git add [-A|-u|-p] <pathspec>... — square brackets mark the parts you can leave out.

Q. How many flags are worth knowing?

6 are listed here; the full set is in man git. This command sits under git.

Related commands

man page: man git-add