Skip to main content

Synopsis

git add [--verbose | -v] [--dry-run | -n] [--force | -f] [--interactive | -i] [--patch | -p]
	[--edit | -e] [--[no-]all | -A | --[no-]ignore-removal | [--update | -u]] [--sparse]
	[--intent-to-add | -N] [--refresh] [--ignore-errors] [--ignore-missing] [--renormalize]
	[--chmod=(+|-)x] [--pathspec-from-file=<file> [--pathspec-file-nul]]
	[--] [<pathspec>...]

Description

Add contents of new or changed files to the index. The “index” (also known as the “staging area”) is what you use to prepare the contents of the next commit. When you run git commit without any other arguments, it will only commit staged changes. This command can be performed multiple times before a commit. It only adds the content of the specified file(s) at the time the add command is run; if you want subsequent changes included in the next commit, then you must run git add again to add the new content to the index. The git status command can be used to obtain a summary of which files have changes that are staged for the next commit.

Common Usage

1

Stage a specific file

Add a single file to the staging area:
git add file.c
2

Stage all changes

Add all modified and new files:
git add .
3

Stage interactively

Use patch mode to selectively stage changes:
git add -p
4

Verify staged changes

Check what has been staged:
git status

Options

<pathspec>...Files to add content from. Fileglobs (e.g. *.c) can be given to add all matching files. A leading directory name (e.g. dir) can be given to update the index to match the current state of the directory as a whole.-n, --dry-runDon’t actually add the file(s), just show if they exist and/or will be ignored.-v, --verboseBe verbose.-f, --forceAllow adding otherwise ignored files.
-i, --interactiveAdd modified contents in the working tree interactively to the index. Optional path arguments may be supplied to limit operation to a subset of the working tree.-p, --patchInteractively choose hunks of patch between the index and the work tree and add them to the index. This gives the user a chance to review the difference before adding modified contents to the index.-e, --editOpen the diff vs. the index in an editor and let the user edit it. After the editor was closed, adjust the hunk headers and apply the patch to the index.
-u, --updateUpdate the index just where it already has an entry matching pathspec. This removes as well as modifies index entries to match the working tree, but adds no new files.-A, --all, --no-ignore-removalUpdate the index not only where the working tree has a file matching pathspec but also where the index already has an entry. This adds, modifies, and removes index entries to match the working tree.--no-all, --ignore-removalUpdate the index by adding new files that are unknown to the index and files modified in the working tree, but ignore files that have been removed from the working tree.
-N, --intent-to-addRecord only the fact that the path will be added later. An entry for the path is placed in the index with no content.--refreshDon’t add the file(s), but only refresh their stat() information in the index.--ignore-errorsIf some files could not be added because of errors indexing them, do not abort the operation, but continue adding the others.--chmod=(+|-)xOverride the executable bit of the added files. The executable bit is only changed in the index, the files on disk are left unchanged.--renormalizeApply the “clean” process freshly to all tracked files to forcibly add them again to the index. This is useful after changing core.autocrlf configuration or the text attribute.--sparseAllow updating index entries outside of the sparse-checkout cone. Normally, git add refuses to update index entries whose paths do not fit within the sparse-checkout cone.

Examples

Add all text files in Documentation directory

$ git add Documentation/\*.txt
Note that the asterisk * is quoted from the shell in this example; this lets the command include the files from subdirectories of Documentation/ directory.

Add all git shell scripts

$ git add git-*.sh
Because this example lets the shell expand the asterisk (i.e. you are listing the files explicitly), it does not consider subdir/git-foo.sh.

Stage partial changes

$ git add -p file.c
This will interactively let you choose which hunks to stage.

Add all changes including deletions

$ git add -A
This stages all changes in the entire working tree, including new files, modifications, and deletions.

Interactive Mode

When the command enters the interactive mode with -i, it shows the output of the status subcommand and then goes into an interactive command loop with these subcommands:
  • status - Show the change between HEAD and index, and between index and working tree files
  • update - Add working tree changes to the index
  • revert - Revert staged changes back to HEAD version
  • add untracked - Add untracked paths to the index
  • patch - Interactively choose hunks to stage
  • diff - Review what will be committed
  • git status - Show the working tree status
  • git commit - Record changes to the repository
  • git rm - Remove files from the working tree and index
  • git reset - Reset current HEAD to the specified state
  • git mv - Move or rename a file, directory, or symlink