1GIT-ADD(1)                        Git Manual                        GIT-ADD(1)
2
3
4

NAME

6       git-add - Add file contents to the index
7

SYNOPSIS

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

DESCRIPTION

16       This command updates the index using the current content found in the
17       working tree, to prepare the content staged for the next commit. It
18       typically adds the current content of existing paths as a whole, but
19       with some options it can also be used to add content with only part of
20       the changes made to the working tree files applied, or remove paths
21       that do not exist in the working tree anymore.
22
23       The "index" holds a snapshot of the content of the working tree, and it
24       is this snapshot that is taken as the contents of the next commit. Thus
25       after making any changes to the working tree, and before running the
26       commit command, you must use the add command to add any new or modified
27       files to the index.
28
29       This command can be performed multiple times before a commit. It only
30       adds the content of the specified file(s) at the time the add command
31       is run; if you want subsequent changes included in the next commit,
32       then you must run git add again to add the new content to the index.
33
34       The git status command can be used to obtain a summary of which files
35       have changes that are staged for the next commit.
36
37       The git add command will not add ignored files by default. If any
38       ignored files were explicitly specified on the command line, git add
39       will fail with a list of ignored files. Ignored files reached by
40       directory recursion or filename globbing performed by Git (quote your
41       globs before the shell) will be silently ignored. The git add command
42       can be used to add ignored files with the -f (force) option.
43
44       Please see git-commit(1) for alternative ways to add content to a
45       commit.
46

OPTIONS

48       <pathspec>...
49           Files to add content from. Fileglobs (e.g.  *.c) can be given to
50           add all matching files. Also a leading directory name (e.g.  dir to
51           add dir/file1 and dir/file2) can be given to update the index to
52           match the current state of the directory as a whole (e.g.
53           specifying dir will record not just a file dir/file1 modified in
54           the working tree, a file dir/file2 added to the working tree, but
55           also a file dir/file3 removed from the working tree). Note that
56           older versions of Git used to ignore removed files; use --no-all
57           option if you want to add modified or new files but ignore removed
58           ones.
59
60           For more details about the <pathspec> syntax, see the pathspec
61           entry in gitglossary(7).
62
63       -n, --dry-run
64           Don’t actually add the file(s), just show if they exist and/or will
65           be ignored.
66
67       -v, --verbose
68           Be verbose.
69
70       -f, --force
71           Allow adding otherwise ignored files.
72
73       --sparse
74           Allow updating index entries outside of the sparse-checkout cone.
75           Normally, git add refuses to update index entries whose paths do
76           not fit within the sparse-checkout cone, since those files might be
77           removed from the working tree without warning. See git-sparse-
78           checkout(1) for more details.
79
80       -i, --interactive
81           Add modified contents in the working tree interactively to the
82           index. Optional path arguments may be supplied to limit operation
83           to a subset of the working tree. See “Interactive mode” for
84           details.
85
86       -p, --patch
87           Interactively choose hunks of patch between the index and the work
88           tree and add them to the index. This gives the user a chance to
89           review the difference before adding modified contents to the index.
90
91           This effectively runs add --interactive, but bypasses the initial
92           command menu and directly jumps to the patch subcommand. See
93           “Interactive mode” for details.
94
95       -e, --edit
96           Open the diff vs. the index in an editor and let the user edit it.
97           After the editor was closed, adjust the hunk headers and apply the
98           patch to the index.
99
100           The intent of this option is to pick and choose lines of the patch
101           to apply, or even to modify the contents of lines to be staged.
102           This can be quicker and more flexible than using the interactive
103           hunk selector. However, it is easy to confuse oneself and create a
104           patch that does not apply to the index. See EDITING PATCHES below.
105
106       -u, --update
107           Update the index just where it already has an entry matching
108           <pathspec>. This removes as well as modifies index entries to match
109           the working tree, but adds no new files.
110
111           If no <pathspec> is given when -u option is used, all tracked files
112           in the entire working tree are updated (old versions of Git used to
113           limit the update to the current directory and its subdirectories).
114
115       -A, --all, --no-ignore-removal
116           Update the index not only where the working tree has a file
117           matching <pathspec> but also where the index already has an entry.
118           This adds, modifies, and removes index entries to match the working
119           tree.
120
121           If no <pathspec> is given when -A option is used, all files in the
122           entire working tree are updated (old versions of Git used to limit
123           the update to the current directory and its subdirectories).
124
125       --no-all, --ignore-removal
126           Update the index by adding new files that are unknown to the index
127           and files modified in the working tree, but ignore files that have
128           been removed from the working tree. This option is a no-op when no
129           <pathspec> is used.
130
131           This option is primarily to help users who are used to older
132           versions of Git, whose "git add <pathspec>..." was a synonym for
133           "git add --no-all <pathspec>...", i.e. ignored removed files.
134
135       -N, --intent-to-add
136           Record only the fact that the path will be added later. An entry
137           for the path is placed in the index with no content. This is useful
138           for, among other things, showing the unstaged content of such files
139           with git diff and committing them with git commit -a.
140
141       --refresh
142           Don’t add the file(s), but only refresh their stat() information in
143           the index.
144
145       --ignore-errors
146           If some files could not be added because of errors indexing them,
147           do not abort the operation, but continue adding the others. The
148           command shall still exit with non-zero status. The configuration
149           variable add.ignoreErrors can be set to true to make this the
150           default behaviour.
151
152       --ignore-missing
153           This option can only be used together with --dry-run. By using this
154           option the user can check if any of the given files would be
155           ignored, no matter if they are already present in the work tree or
156           not.
157
158       --no-warn-embedded-repo
159           By default, git add will warn when adding an embedded repository to
160           the index without using git submodule add to create an entry in
161           .gitmodules. This option will suppress the warning (e.g., if you
162           are manually performing operations on submodules).
163
164       --renormalize
165           Apply the "clean" process freshly to all tracked files to forcibly
166           add them again to the index. This is useful after changing
167           core.autocrlf configuration or the text attribute in order to
168           correct files added with wrong CRLF/LF line endings. This option
169           implies -u. Lone CR characters are untouched, thus while a CRLF
170           cleans to LF, a CRCRLF sequence is only partially cleaned to CRLF.
171
172       --chmod=(+|-)x
173           Override the executable bit of the added files. The executable bit
174           is only changed in the index, the files on disk are left unchanged.
175
176       --pathspec-from-file=<file>
177           Pathspec is passed in <file> instead of commandline args. If <file>
178           is exactly - then standard input is used. Pathspec elements are
179           separated by LF or CR/LF. Pathspec elements can be quoted as
180           explained for the configuration variable core.quotePath (see git-
181           config(1)). See also --pathspec-file-nul and global
182           --literal-pathspecs.
183
184       --pathspec-file-nul
185           Only meaningful with --pathspec-from-file. Pathspec elements are
186           separated with NUL character and all other characters are taken
187           literally (including newlines and quotes).
188
189       --
190           This option can be used to separate command-line options from the
191           list of files, (useful when filenames might be mistaken for
192           command-line options).
193

EXAMPLES

195       •   Adds content from all *.txt files under Documentation directory and
196           its subdirectories:
197
198               $ git add Documentation/\*.txt
199
200           Note that the asterisk * is quoted from the shell in this example;
201           this lets the command include the files from subdirectories of
202           Documentation/ directory.
203
204       •   Considers adding content from all git-*.sh scripts:
205
206               $ git add git-*.sh
207
208           Because this example lets the shell expand the asterisk (i.e. you
209           are listing the files explicitly), it does not consider
210           subdir/git-foo.sh.
211

INTERACTIVE MODE

213       When the command enters the interactive mode, it shows the output of
214       the status subcommand, and then goes into its interactive command loop.
215
216       The command loop shows the list of subcommands available, and gives a
217       prompt "What now> ". In general, when the prompt ends with a single >,
218       you can pick only one of the choices given and type return, like this:
219
220               *** Commands ***
221                 1: status       2: update       3: revert       4: add untracked
222                 5: patch        6: diff         7: quit         8: help
223               What now> 1
224
225       You also could say s or sta or status above as long as the choice is
226       unique.
227
228       The main command loop has 6 subcommands (plus help and quit).
229
230       status
231           This shows the change between HEAD and index (i.e. what will be
232           committed if you say git commit), and between index and working
233           tree files (i.e. what you could stage further before git commit
234           using git add) for each path. A sample output looks like this:
235
236                             staged     unstaged path
237                    1:       binary      nothing foo.png
238                    2:     +403/-35        +1/-1 add-interactive.c
239
240           It shows that foo.png has differences from HEAD (but that is binary
241           so line count cannot be shown) and there is no difference between
242           indexed copy and the working tree version (if the working tree
243           version were also different, binary would have been shown in place
244           of nothing). The other file, add-interactive.c, has 403 lines added
245           and 35 lines deleted if you commit what is in the index, but
246           working tree file has further modifications (one addition and one
247           deletion).
248
249       update
250           This shows the status information and issues an "Update>>" prompt.
251           When the prompt ends with double >>, you can make more than one
252           selection, concatenated with whitespace or comma. Also you can say
253           ranges. E.g. "2-5 7,9" to choose 2,3,4,5,7,9 from the list. If the
254           second number in a range is omitted, all remaining patches are
255           taken. E.g. "7-" to choose 7,8,9 from the list. You can say * to
256           choose everything.
257
258           What you chose are then highlighted with *, like this:
259
260                          staged     unstaged path
261                 1:       binary      nothing foo.png
262               * 2:     +403/-35        +1/-1 add-interactive.c
263
264           To remove selection, prefix the input with - like this:
265
266               Update>> -2
267
268           After making the selection, answer with an empty line to stage the
269           contents of working tree files for selected paths in the index.
270
271       revert
272           This has a very similar UI to update, and the staged information
273           for selected paths are reverted to that of the HEAD version.
274           Reverting new paths makes them untracked.
275
276       add untracked
277           This has a very similar UI to update and revert, and lets you add
278           untracked paths to the index.
279
280       patch
281           This lets you choose one path out of a status like selection. After
282           choosing the path, it presents the diff between the index and the
283           working tree file and asks you if you want to stage the change of
284           each hunk. You can select one of the following options and type
285           return:
286
287               y - stage this hunk
288               n - do not stage this hunk
289               q - quit; do not stage this hunk or any of the remaining ones
290               a - stage this hunk and all later hunks in the file
291               d - do not stage this hunk or any of the later hunks in the file
292               g - select a hunk to go to
293               / - search for a hunk matching the given regex
294               j - leave this hunk undecided, see next undecided hunk
295               J - leave this hunk undecided, see next hunk
296               k - leave this hunk undecided, see previous undecided hunk
297               K - leave this hunk undecided, see previous hunk
298               s - split the current hunk into smaller hunks
299               e - manually edit the current hunk
300               ? - print help
301
302           After deciding the fate for all hunks, if there is any hunk that
303           was chosen, the index is updated with the selected hunks.
304
305           You can omit having to type return here, by setting the
306           configuration variable interactive.singleKey to true.
307
308       diff
309           This lets you review what will be committed (i.e. between HEAD and
310           index).
311

EDITING PATCHES

313       Invoking git add -e or selecting e from the interactive hunk selector
314       will open a patch in your editor; after the editor exits, the result is
315       applied to the index. You are free to make arbitrary changes to the
316       patch, but note that some changes may have confusing results, or even
317       result in a patch that cannot be applied. If you want to abort the
318       operation entirely (i.e., stage nothing new in the index), simply
319       delete all lines of the patch. The list below describes some common
320       things you may see in a patch, and which editing operations make sense
321       on them.
322
323       added content
324           Added content is represented by lines beginning with "+". You can
325           prevent staging any addition lines by deleting them.
326
327       removed content
328           Removed content is represented by lines beginning with "-". You can
329           prevent staging their removal by converting the "-" to a " "
330           (space).
331
332       modified content
333           Modified content is represented by "-" lines (removing the old
334           content) followed by "+" lines (adding the replacement content).
335           You can prevent staging the modification by converting "-" lines to
336           " ", and removing "+" lines. Beware that modifying only half of the
337           pair is likely to introduce confusing changes to the index.
338
339       There are also more complex operations that can be performed. But
340       beware that because the patch is applied only to the index and not the
341       working tree, the working tree will appear to "undo" the change in the
342       index. For example, introducing a new line into the index that is in
343       neither the HEAD nor the working tree will stage the new line for
344       commit, but the line will appear to be reverted in the working tree.
345
346       Avoid using these constructs, or do so with extreme caution.
347
348       removing untouched content
349           Content which does not differ between the index and working tree
350           may be shown on context lines, beginning with a " " (space). You
351           can stage context lines for removal by converting the space to a
352           "-". The resulting working tree file will appear to re-add the
353           content.
354
355       modifying existing content
356           One can also modify context lines by staging them for removal (by
357           converting " " to "-") and adding a "+" line with the new content.
358           Similarly, one can modify "+" lines for existing additions or
359           modifications. In all cases, the new modification will appear
360           reverted in the working tree.
361
362       new content
363           You may also add new content that does not exist in the patch;
364           simply add new lines, each starting with "+". The addition will
365           appear reverted in the working tree.
366
367       There are also several operations which should be avoided entirely, as
368       they will make the patch impossible to apply:
369
370       •   adding context (" ") or removal ("-") lines
371
372       •   deleting context or removal lines
373
374       •   modifying the contents of context or removal lines
375

CONFIGURATION

377       Everything below this line in this section is selectively included from
378       the git-config(1) documentation. The content is the same as what’s
379       found there:
380
381       add.ignoreErrors, add.ignore-errors (deprecated)
382           Tells git add to continue adding files when some files cannot be
383           added due to indexing errors. Equivalent to the --ignore-errors
384           option of git-add(1).  add.ignore-errors is deprecated, as it does
385           not follow the usual naming convention for configuration variables.
386
387       add.interactive.useBuiltin
388           Unused configuration variable. Used in Git versions v2.25.0 to
389           v2.36.0 to enable the built-in version of git-add(1)'s interactive
390           mode, which then became the default in Git versions v2.37.0 to
391           v2.39.0.
392

SEE ALSO

394       git-status(1) git-rm(1) git-reset(1) git-mv(1) git-commit(1) git-
395       update-index(1)
396

GIT

398       Part of the git(1) suite
399
400
401
402Git 2.43.0                        11/20/2023                        GIT-ADD(1)
Impressum