{
    "mode": "info",
    "parameter": "git-add",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/info/git-add/json",
    "generated": "2026-07-11T15:50:28Z",
    "synopsis": "git add [--verbose | -v] [--dry-run | -n] [--force | -f] [--interactive | -i] [--patch | -p]\n[--edit | -e] [--[no-]all | --[no-]ignore-removal | [--update | -u]] [--sparse]\n[--intent-to-add | -N] [--refresh] [--ignore-errors] [--ignore-missing] [--renormalize]\n[--chmod=(+|-)x] [--pathspec-from-file=<file> [--pathspec-file-nul]]\n[--] [<pathspec>...]",
    "sections": {
        "NAME": {
            "content": "git-add - Add file contents to the index\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "git add [--verbose | -v] [--dry-run | -n] [--force | -f] [--interactive | -i] [--patch | -p]\n[--edit | -e] [--[no-]all | --[no-]ignore-removal | [--update | -u]] [--sparse]\n[--intent-to-add | -N] [--refresh] [--ignore-errors] [--ignore-missing] [--renormalize]\n[--chmod=(+|-)x] [--pathspec-from-file=<file> [--pathspec-file-nul]]\n[--] [<pathspec>...]\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "This command updates the index using the current content found in the\nworking tree, to prepare the content staged for the next commit. It\ntypically adds the current content of existing paths as a whole, but\nwith some options it can also be used to add content with only part of\nthe changes made to the working tree files applied, or remove paths\nthat do not exist in the working tree anymore.\n\nThe \"index\" holds a snapshot of the content of the working tree, and it\nis this snapshot that is taken as the contents of the next commit. Thus\nafter making any changes to the working tree, and before running the\ncommit command, you must use the add command to add any new or modified\nfiles to the index.\n\nThis command can be performed multiple times before a commit. It only\nadds the content of the specified file(s) at the time the add command\nis run; if you want subsequent changes included in the next commit,\nthen you must run git add again to add the new content to the index.\n\nThe git status command can be used to obtain a summary of which files\nhave changes that are staged for the next commit.\n\nThe git add command will not add ignored files by default. If any\nignored files were explicitly specified on the command line, git add\nwill fail with a list of ignored files. Ignored files reached by\ndirectory recursion or filename globbing performed by Git (quote your\nglobs before the shell) will be silently ignored. The git add command\ncan be used to add ignored files with the -f (force) option.\n\nPlease see git-commit(1) for alternative ways to add content to a\ncommit.\n",
            "subsections": []
        },
        "OPTIONS": {
            "content": "<pathspec>...\nFiles to add content from. Fileglobs (e.g.  *.c) can be given to\nadd all matching files. Also a leading directory name (e.g.  dir to\nadd dir/file1 and dir/file2) can be given to update the index to\nmatch the current state of the directory as a whole (e.g.\nspecifying dir will record not just a file dir/file1 modified in\nthe working tree, a file dir/file2 added to the working tree, but\nalso a file dir/file3 removed from the working tree). Note that\nolder versions of Git used to ignore removed files; use --no-all\noption if you want to add modified or new files but ignore removed\nones.\n\nFor more details about the <pathspec> syntax, see the pathspec\nentry in gitglossary(7).\n",
            "subsections": [
                {
                    "name": "-n, --dry-run",
                    "content": "Don't actually add the file(s), just show if they exist and/or will\nbe ignored.\n",
                    "flag": "-n",
                    "long": "--dry-run"
                },
                {
                    "name": "-v, --verbose",
                    "content": "Be verbose.\n",
                    "flag": "-v",
                    "long": "--verbose"
                },
                {
                    "name": "-f, --force",
                    "content": "Allow adding otherwise ignored files.\n",
                    "flag": "-f",
                    "long": "--force"
                },
                {
                    "name": "--sparse",
                    "content": "Allow updating index entries outside of the sparse-checkout cone.\nNormally, git add refuses to update index entries whose paths do\nnot fit within the sparse-checkout cone, since those files might be\nremoved from the working tree without warning. See git-sparse-\ncheckout(1) for more details.\n",
                    "long": "--sparse"
                },
                {
                    "name": "-i, --interactive",
                    "content": "Add modified contents in the working tree interactively to the\nindex. Optional path arguments may be supplied to limit operation\nto a subset of the working tree. See \"Interactive mode\" for\ndetails.\n",
                    "flag": "-i",
                    "long": "--interactive"
                },
                {
                    "name": "-p, --patch",
                    "content": "Interactively choose hunks of patch between the index and the work\ntree and add them to the index. This gives the user a chance to\nreview the difference before adding modified contents to the index.\n\nThis effectively runs add --interactive, but bypasses the initial\ncommand menu and directly jumps to the patch subcommand. See\n\"Interactive mode\" for details.\n",
                    "flag": "-p",
                    "long": "--patch"
                },
                {
                    "name": "-e, --edit",
                    "content": "Open the diff vs. the index in an editor and let the user edit it.\nAfter the editor was closed, adjust the hunk headers and apply the\npatch to the index.\n\nThe intent of this option is to pick and choose lines of the patch\nto apply, or even to modify the contents of lines to be staged.\nThis can be quicker and more flexible than using the interactive\nhunk selector. However, it is easy to confuse oneself and create a\npatch that does not apply to the index. See EDITING PATCHES below.\n",
                    "flag": "-e",
                    "long": "--edit"
                },
                {
                    "name": "-u, --update",
                    "content": "Update the index just where it already has an entry matching\n<pathspec>. This removes as well as modifies index entries to match\nthe working tree, but adds no new files.\n\nIf no <pathspec> is given when -u option is used, all tracked files\nin the entire working tree are updated (old versions of Git used to\nlimit the update to the current directory and its subdirectories).\n",
                    "flag": "-u",
                    "long": "--update"
                },
                {
                    "name": "-A, --all, --no-ignore-removal",
                    "content": "Update the index not only where the working tree has a file\nmatching <pathspec> but also where the index already has an entry.\nThis adds, modifies, and removes index entries to match the working\ntree.\n\nIf no <pathspec> is given when -A option is used, all files in the\nentire working tree are updated (old versions of Git used to limit\nthe update to the current directory and its subdirectories).\n",
                    "flag": "-A",
                    "long": "--no-ignore-removal"
                },
                {
                    "name": "--no-all, --ignore-removal",
                    "content": "Update the index by adding new files that are unknown to the index\nand files modified in the working tree, but ignore files that have\nbeen removed from the working tree. This option is a no-op when no\n<pathspec> is used.\n\nThis option is primarily to help users who are used to older\nversions of Git, whose \"git add <pathspec>...\" was a synonym for\n\"git add --no-all <pathspec>...\", i.e. ignored removed files.\n",
                    "long": "--ignore-removal"
                },
                {
                    "name": "-N, --intent-to-add",
                    "content": "Record only the fact that the path will be added later. An entry\nfor the path is placed in the index with no content. This is useful\nfor, among other things, showing the unstaged content of such files\nwith git diff and committing them with git commit -a.\n",
                    "flag": "-N",
                    "long": "--intent-to-add"
                },
                {
                    "name": "--refresh",
                    "content": "Don't add the file(s), but only refresh their stat() information in\nthe index.\n",
                    "long": "--refresh"
                },
                {
                    "name": "--ignore-errors",
                    "content": "If some files could not be added because of errors indexing them,\ndo not abort the operation, but continue adding the others. The\ncommand shall still exit with non-zero status. The configuration\nvariable add.ignoreErrors can be set to true to make this the\ndefault behaviour.\n",
                    "long": "--ignore-errors"
                },
                {
                    "name": "--ignore-missing",
                    "content": "This option can only be used together with --dry-run. By using this\noption the user can check if any of the given files would be\nignored, no matter if they are already present in the work tree or\nnot.\n",
                    "long": "--ignore-missing"
                },
                {
                    "name": "--no-warn-embedded-repo",
                    "content": "By default, git add will warn when adding an embedded repository to\nthe index without using git submodule add to create an entry in\n.gitmodules. This option will suppress the warning (e.g., if you\nare manually performing operations on submodules).\n",
                    "long": "--no-warn-embedded-repo"
                },
                {
                    "name": "--renormalize",
                    "content": "Apply the \"clean\" process freshly to all tracked files to forcibly\nadd them again to the index. This is useful after changing\ncore.autocrlf configuration or the text attribute in order to\ncorrect files added with wrong CRLF/LF line endings. This option\nimplies -u.\n\n--chmod=(+|-)x\nOverride the executable bit of the added files. The executable bit\nis only changed in the index, the files on disk are left unchanged.\n\n--pathspec-from-file=<file>\nPathspec is passed in <file> instead of commandline args. If <file>\nis exactly - then standard input is used. Pathspec elements are\nseparated by LF or CR/LF. Pathspec elements can be quoted as\nexplained for the configuration variable core.quotePath (see git-\nconfig(1)). See also --pathspec-file-nul and global\n--literal-pathspecs.\n",
                    "long": "--renormalize"
                },
                {
                    "name": "--pathspec-file-nul",
                    "content": "Only meaningful with --pathspec-from-file. Pathspec elements are\nseparated with NUL character and all other characters are taken\nliterally (including newlines and quotes).\n\n--\nThis option can be used to separate command-line options from the\nlist of files, (useful when filenames might be mistaken for\ncommand-line options).\n",
                    "long": "--pathspec-file-nul"
                }
            ]
        },
        "EXAMPLES": {
            "content": "o   Adds content from all *.txt files under Documentation directory and\nits subdirectories:\n\n$ git add Documentation/\\*.txt\n\nNote that the asterisk * is quoted from the shell in this example;\nthis lets the command include the files from subdirectories of\nDocumentation/ directory.\n\no   Considers adding content from all git-*.sh scripts:\n\n$ git add git-*.sh\n\nBecause this example lets the shell expand the asterisk (i.e. you\nare listing the files explicitly), it does not consider\nsubdir/git-foo.sh.\n",
            "subsections": []
        },
        "INTERACTIVE MODE": {
            "content": "When the command enters the interactive mode, it shows the output of\nthe status subcommand, and then goes into its interactive command loop.\n\nThe command loop shows the list of subcommands available, and gives a\nprompt \"What now> \". In general, when the prompt ends with a single >,\nyou can pick only one of the choices given and type return, like this:\n\n* Commands *\n1: status       2: update       3: revert       4: add untracked\n5: patch        6: diff         7: quit         8: help\nWhat now> 1\n\nYou also could say s or sta or status above as long as the choice is\nunique.\n\nThe main command loop has 6 subcommands (plus help and quit).\n\nstatus\nThis shows the change between HEAD and index (i.e. what will be\ncommitted if you say git commit), and between index and working\ntree files (i.e. what you could stage further before git commit\nusing git add) for each path. A sample output looks like this:\n\nstaged     unstaged path\n1:       binary      nothing foo.png\n2:     +403/-35        +1/-1 git-add--interactive.perl\n\nIt shows that foo.png has differences from HEAD (but that is binary\nso line count cannot be shown) and there is no difference between\nindexed copy and the working tree version (if the working tree\nversion were also different, binary would have been shown in place\nof nothing). The other file, git-add--interactive.perl, has 403\nlines added and 35 lines deleted if you commit what is in the\nindex, but working tree file has further modifications (one\naddition and one deletion).\n\nupdate\nThis shows the status information and issues an \"Update>>\" prompt.\nWhen the prompt ends with double >>, you can make more than one\nselection, concatenated with whitespace or comma. Also you can say\nranges. E.g. \"2-5 7,9\" to choose 2,3,4,5,7,9 from the list. If the\nsecond number in a range is omitted, all remaining patches are\ntaken. E.g. \"7-\" to choose 7,8,9 from the list. You can say * to\nchoose everything.\n\nWhat you chose are then highlighted with *, like this:\n\nstaged     unstaged path\n1:       binary      nothing foo.png\n* 2:     +403/-35        +1/-1 git-add--interactive.perl\n\nTo remove selection, prefix the input with - like this:\n\nUpdate>> -2\n\nAfter making the selection, answer with an empty line to stage the\ncontents of working tree files for selected paths in the index.\n\nrevert\nThis has a very similar UI to update, and the staged information\nfor selected paths are reverted to that of the HEAD version.\nReverting new paths makes them untracked.\n\nadd untracked\nThis has a very similar UI to update and revert, and lets you add\nuntracked paths to the index.\n\npatch\nThis lets you choose one path out of a status like selection. After\nchoosing the path, it presents the diff between the index and the\nworking tree file and asks you if you want to stage the change of\neach hunk. You can select one of the following options and type\nreturn:\n\ny - stage this hunk\nn - do not stage this hunk\nq - quit; do not stage this hunk or any of the remaining ones\na - stage this hunk and all later hunks in the file\nd - do not stage this hunk or any of the later hunks in the file\ng - select a hunk to go to\n/ - search for a hunk matching the given regex\nj - leave this hunk undecided, see next undecided hunk\nJ - leave this hunk undecided, see next hunk\nk - leave this hunk undecided, see previous undecided hunk\nK - leave this hunk undecided, see previous hunk\ns - split the current hunk into smaller hunks\ne - manually edit the current hunk\n? - print help\n\nAfter deciding the fate for all hunks, if there is any hunk that\nwas chosen, the index is updated with the selected hunks.\n\nYou can omit having to type return here, by setting the\nconfiguration variable interactive.singleKey to true.\n\ndiff\nThis lets you review what will be committed (i.e. between HEAD and\nindex).\n",
            "subsections": []
        },
        "EDITING PATCHES": {
            "content": "Invoking git add -e or selecting e from the interactive hunk selector\nwill open a patch in your editor; after the editor exits, the result is\napplied to the index. You are free to make arbitrary changes to the\npatch, but note that some changes may have confusing results, or even\nresult in a patch that cannot be applied. If you want to abort the\noperation entirely (i.e., stage nothing new in the index), simply\ndelete all lines of the patch. The list below describes some common\nthings you may see in a patch, and which editing operations make sense\non them.\n\nadded content\nAdded content is represented by lines beginning with \"+\". You can\nprevent staging any addition lines by deleting them.\n\nremoved content\nRemoved content is represented by lines beginning with \"-\". You can\nprevent staging their removal by converting the \"-\" to a \" \"\n(space).\n\nmodified content\nModified content is represented by \"-\" lines (removing the old\ncontent) followed by \"+\" lines (adding the replacement content).\nYou can prevent staging the modification by converting \"-\" lines to\n\" \", and removing \"+\" lines. Beware that modifying only half of the\npair is likely to introduce confusing changes to the index.\n\nThere are also more complex operations that can be performed. But\nbeware that because the patch is applied only to the index and not the\nworking tree, the working tree will appear to \"undo\" the change in the\nindex. For example, introducing a new line into the index that is in\nneither the HEAD nor the working tree will stage the new line for\ncommit, but the line will appear to be reverted in the working tree.\n\nAvoid using these constructs, or do so with extreme caution.\n\nremoving untouched content\nContent which does not differ between the index and working tree\nmay be shown on context lines, beginning with a \" \" (space). You\ncan stage context lines for removal by converting the space to a\n\"-\". The resulting working tree file will appear to re-add the\ncontent.\n\nmodifying existing content\nOne can also modify context lines by staging them for removal (by\nconverting \" \" to \"-\") and adding a \"+\" line with the new content.\nSimilarly, one can modify \"+\" lines for existing additions or\nmodifications. In all cases, the new modification will appear\nreverted in the working tree.\n\nnew content\nYou may also add new content that does not exist in the patch;\nsimply add new lines, each starting with \"+\". The addition will\nappear reverted in the working tree.\n\nThere are also several operations which should be avoided entirely, as\nthey will make the patch impossible to apply:\n\no   adding context (\" \") or removal (\"-\") lines\n\no   deleting context or removal lines\n\no   modifying the contents of context or removal lines\n",
            "subsections": []
        },
        "SEE ALSO": {
            "content": "git-status(1) git-rm(1) git-reset(1) git-mv(1) git-commit(1) git-\nupdate-index(1)\n",
            "subsections": []
        },
        "GIT": {
            "content": "Part of the git(1) suite\n\nGit 2.34.1                        02/26/2026                        GIT-ADD(1)",
            "subsections": []
        }
    },
    "summary": "git-add - Add file contents to the index",
    "flags": [
        {
            "flag": "-n",
            "long": "--dry-run",
            "arg": null,
            "description": "Don't actually add the file(s), just show if they exist and/or will be ignored."
        },
        {
            "flag": "-v",
            "long": "--verbose",
            "arg": null,
            "description": "Be verbose."
        },
        {
            "flag": "-f",
            "long": "--force",
            "arg": null,
            "description": "Allow adding otherwise ignored files."
        },
        {
            "flag": "",
            "long": "--sparse",
            "arg": null,
            "description": "Allow 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, since those files might be removed from the working tree without warning. See git-sparse- checkout(1) for more details."
        },
        {
            "flag": "-i",
            "long": "--interactive",
            "arg": null,
            "description": "Add 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. See \"Interactive mode\" for details."
        },
        {
            "flag": "-p",
            "long": "--patch",
            "arg": null,
            "description": "Interactively 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. This effectively runs add --interactive, but bypasses the initial command menu and directly jumps to the patch subcommand. See \"Interactive mode\" for details."
        },
        {
            "flag": "-e",
            "long": "--edit",
            "arg": null,
            "description": "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 apply the 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 be staged. This can be quicker and more flexible than using the interactive hunk selector. However, it is easy to confuse oneself and create a patch that does not apply to the index. See EDITING PATCHES below."
        },
        {
            "flag": "-u",
            "long": "--update",
            "arg": null,
            "description": "Update 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. If no <pathspec> is given when -u option is used, all tracked files in the entire working tree are updated (old versions of Git used to limit the update to the current directory and its subdirectories)."
        },
        {
            "flag": "-A",
            "long": "--no-ignore-removal",
            "arg": null,
            "description": "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 to limit the update to the current directory and its subdirectories)."
        },
        {
            "flag": "",
            "long": "--ignore-removal",
            "arg": null,
            "description": "Update 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. This option is a no-op when no <pathspec> is used. This option is primarily to help users who are used to older versions of Git, whose \"git add <pathspec>...\" was a synonym for \"git add --no-all <pathspec>...\", i.e. ignored removed files."
        },
        {
            "flag": "-N",
            "long": "--intent-to-add",
            "arg": null,
            "description": "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 is useful for, among other things, showing the unstaged content of such files with git diff and committing them with git commit -a."
        },
        {
            "flag": "",
            "long": "--refresh",
            "arg": null,
            "description": "Don't add the file(s), but only refresh their stat() information in the index."
        },
        {
            "flag": "",
            "long": "--ignore-errors",
            "arg": null,
            "description": "If some files could not be added because of errors indexing them, do not abort the operation, but continue adding the others. The command shall still exit with non-zero status. The configuration variable add.ignoreErrors can be set to true to make this the default behaviour."
        },
        {
            "flag": "",
            "long": "--ignore-missing",
            "arg": null,
            "description": "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 be ignored, no matter if they are already present in the work tree or not."
        },
        {
            "flag": "",
            "long": "--no-warn-embedded-repo",
            "arg": null,
            "description": "By default, git add will warn when adding an embedded repository to the index without using git submodule add to create an entry in .gitmodules. This option will suppress the warning (e.g., if you are manually performing operations on submodules)."
        },
        {
            "flag": "",
            "long": "--renormalize",
            "arg": null,
            "description": "Apply 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 in order to correct files added with wrong CRLF/LF line endings. This option implies -u. --chmod=(+|-)x Override the executable bit of the added files. The executable bit is only changed in the index, the files on disk are left unchanged. --pathspec-from-file=<file> Pathspec is passed in <file> instead of commandline args. If <file> is exactly - then standard input is used. Pathspec elements are separated by LF or CR/LF. Pathspec elements can be quoted as explained for the configuration variable core.quotePath (see git- config(1)). See also --pathspec-file-nul and global --literal-pathspecs."
        },
        {
            "flag": "",
            "long": "--pathspec-file-nul",
            "arg": null,
            "description": "Only meaningful with --pathspec-from-file. Pathspec elements are separated with NUL character and all other characters are taken literally (including newlines and quotes). -- This option can be used to separate command-line options from the list of files, (useful when filenames might be mistaken for command-line options)."
        }
    ],
    "examples": [
        "o   Adds content from all *.txt files under Documentation directory and",
        "its subdirectories:",
        "$ 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.",
        "o   Considers adding content from all git-*.sh 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."
    ],
    "see_also": [
        {
            "name": "git-status",
            "section": "1",
            "url": "https://www.chedong.com/phpMan.php/man/git-status/1/json"
        },
        {
            "name": "git-rm",
            "section": "1",
            "url": "https://www.chedong.com/phpMan.php/man/git-rm/1/json"
        },
        {
            "name": "git-reset",
            "section": "1",
            "url": "https://www.chedong.com/phpMan.php/man/git-reset/1/json"
        },
        {
            "name": "git-mv",
            "section": "1",
            "url": "https://www.chedong.com/phpMan.php/man/git-mv/1/json"
        },
        {
            "name": "git-commit",
            "section": "1",
            "url": "https://www.chedong.com/phpMan.php/man/git-commit/1/json"
        },
        {
            "name": "update-index",
            "section": "1",
            "url": "https://www.chedong.com/phpMan.php/man/update-index/1/json"
        }
    ]
}