Synopsis
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 rungit 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
Options
Basic Options
Basic 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.Interactive Options
Interactive Options
-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.Update Options
Update Options
-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.Advanced Options
Advanced Options
-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
* 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
subdir/git-foo.sh.
Stage partial changes
Add all changes including 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
Related Commands
- 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
