Linux "git-add" Command Line Options and Examples
Add file contents to the index

This command updates the index using the current content found in the working tree, to prepare the content staged for the next commit.


Usage:

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






Command Line Options:

--no-all
For more details about the <pathspec> syntax, see the pathspec entry in gitglossary(7).
git-add --no-all ...
-n
Don’t actually add the file(s), just show if they exist and/or will be ignored.
git-add -n ...
-f
Allow adding otherwise ignored files.
git-add -f ...
-i
Add modified contents in the working tree interactively to the index. Optional path arguments may be supplied to limit operationto a subset of the working tree. See “Interactive mode” for details.
git-add -i ...
-p
Interactively choose hunks of patch between the index and the work tree and add them to the index. This gives the user a chanceto review the difference before adding modified contents to the index.This effectively runs add --interactive, but bypasses the initial command menu and directly jumps to the patch subcommand. See“Interactive mode” for details.
git-add -p ...
-e
Open the diff vs. the index in an editor and let the user edit it. After the editor was closed, adjust the hunk headers and applythe patch to the index.The intent of this option is to pick and choose lines of the patch to apply, or even to modify the contents of lines to bestaged. This can be quicker and more flexible than using the interactive hunk selector. However, it is easy to confuse oneselfand create a patch that does not apply to the index. See EDITING PATCHES below.
git-add -e ...
-u
Update the index just where it already has an entry matching <pathspec>. This removes as well as modifies index entries to matchthe working tree, but adds no new files.If no <pathspec> is given when -u option is used, all tracked files in the entire working tree are updated (old versions of Gitused to limit the update to the current directory and its subdirectories).
git-add -u ...
-A
Update 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.If no <pathspec> is given when -A option is used, all files in the entire working tree are updated (old versions of Git used tolimit the update to the current directory and its subdirectories).
git-add -A ...
-N
Record only the fact that the path will be added later. An entry for the path is placed in the index with no content. This isuseful for, among other things, showing the unstaged content of such files with git diff and committing them with git commit -a.
git-add -N ...
--refresh
Don’t add the file(s), but only refresh their stat() information in the index.
git-add --refresh ...
--ignore-errors
If some files could not be added because of errors indexing them, do not abort the operation, but continue adding the others. Thecommand shall still exit with non-zero status. The configuration variable add.ignoreErrors can be set to true to make this thedefault behaviour.
git-add --ignore-errors ...
--ignore-missing
This option can only be used together with --dry-run. By using this option the user can check if any of the given files would beignored, no matter if they are already present in the work tree or not.
git-add --ignore-missing ...
--no-warn-embedded-repo
By default, git add will warn when adding an embedded repository to the index without using git submodule add to create an entryin .gitmodules. This option will suppress the warning (e.g., if you are manually performing operations on submodules).
git-add --no-warn-embedded-repo ...
--renormalize
Apply the "clean" process freshly to all tracked files to forcibly add them again to the index. This is useful after changingcore.autocrlf configuration or the text attribute in order to correct files added with wrong CRLF/LF line endings. This optionimplies -u.
git-add --renormalize ...
--chmod
Override the executable bit of the added files. The executable bit is only changed in the index, the files on disk are leftunchanged.
git-add --chmod ...
--
This option can be used to separate command-line options from the list of files, (useful when filenames might be mistaken forcommand-line options).CONFIGURATIONThe optional configuration variable core.excludesFile indicates a path to a file containing patterns of file names to exclude fromgit-add, similar to $GIT_DIR/info/exclude. Patterns in the exclude file are used in addition to those in info/exclude. Seegitignore(5).EXAMPLES· Adds content from all *.txt files under Documentation directory and its subdirectories:$ git add Documentation/\*.txtNote that the asterisk * is quoted from the shell in this example; this lets the command include the files from subdirectories ofDocumentation/ directory.· Considers adding content from all git-*.sh scripts:$ git add git-*.shBecause this example lets the shell expand the asterisk (i.e. you are listing the files explicitly), it does not considersubdir/git-foo.sh.INTERACTIVE MODEWhen the command enters the interactive mode, it shows the output of the status subcommand, and then goes into its interactivecommand loop.The command loop shows the list of subcommands available, and gives a prompt "What now> ". In general, when the prompt ends with asingle >, you can pick only one of the choices given and type return, like this:*** Commands ***1: status 2: update 3: revert 4: add untracked5: patch 6: diff 7: quit 8: helpWhat now> 1You also could say s or sta or status above as long as the choice is unique.The main command loop has 6 subcommands (plus help and quit).statusThis shows the change between HEAD and index (i.e. what will be committed if you say git commit), and between index and workingtree files (i.e. what you could stage further before git commit using git add) for each path. A sample output looks like this:staged unstaged path1: binary nothing foo.png2: +403/-35 +1/-1 git-add--interactive.perlIt shows that foo.png has differences from HEAD (but that is binary so line count cannot be shown) and there is no differencebetween indexed copy and the working tree version (if the working tree version were also different, binary would have been shownin place of nothing). The other file, git-add--interactive.perl, has 403 lines added and 35 lines deleted if you commit what isin the index, but working tree file has further modifications (one addition and one deletion).updateThis shows the status information and issues an "Update>>" prompt. When the prompt ends with double >>, you can make more thanone selection, concatenated with whitespace or comma. Also you can say ranges. E.g. "2-5 7,9" to choose 2,3,4,5,7,9 from thelist. If the second number in a range is omitted, all remaining patches are taken. E.g. "7-" to choose 7,8,9 from the list. Youcan say * to choose everything.What you chose are then highlighted with *, like this:staged unstaged path1: binary nothing foo.png* 2: +403/-35 +1/-1 git-add--interactive.perlTo remove selection, prefix the input with - like this:Update>> -2After making the selection, answer with an empty line to stage the contents of working tree files for selected paths in theindex.revertThis has a very similar UI to update, and the staged information for selected paths are reverted to that of the HEAD version.Reverting new paths makes them untracked.add untrackedThis has a very similar UI to update and revert, and lets you add untracked paths to the index.patchThis lets you choose one path out of a status like selection. After choosing the path, it presents the diff between the index andthe working tree file and asks you if you want to stage the change of each hunk. You can select one of the following options andtype return:
git-add -- ...
-
do not stage this hunk
git-add - ...