{
    "content": [
        {
            "type": "text",
            "text": "# git-rm (man)\n\n## NAME\n\ngit-rm - Remove files from the working tree and from the index\n\n## SYNOPSIS\n\ngit rm [-f | --force] [-n] [-r] [--cached] [--ignore-unmatch]\n[--quiet] [--pathspec-from-file=<file> [--pathspec-file-nul]]\n[--] [<pathspec>...]\n\n## DESCRIPTION\n\nRemove files matching pathspec from the index, or from the working tree and the index. git rm\nwill not remove a file from just your working directory. (There is no option to remove a file\nonly from the working tree and yet keep it in the index; use /bin/rm if you want to do that.)\nThe files being removed have to be identical to the tip of the branch, and no updates to\ntheir contents can be staged in the index, though that default behavior can be overridden\nwith the -f option. When --cached is given, the staged content has to match either the tip of\nthe branch or the file on disk, allowing the file to be removed from just the index. When\nsparse-checkouts are in use (see git-sparse-checkout(1)), git rm will only remove paths\nwithin the sparse-checkout patterns.\n\n## TLDR\n\n> Remove files from repository index and local filesystem.\n\n- Remove file from repository index and filesystem:\n  `git rm {{path/to/file}}`\n- Remove directory [r]ecursively:\n  `git rm -r {{path/to/directory}}`\n- Remove file from repository index but keep it untouched locally:\n  `git rm --cached {{path/to/file}}`\n- Reduce the repository to only the `.git` directory:\n  `git rm -r .`\n\n*Source: tldr-pages*\n\n## Sections\n\n- **NAME**\n- **SYNOPSIS**\n- **DESCRIPTION**\n- **OPTIONS** (10 subsections)\n- **SUBMODULES**\n- **EXAMPLES**\n- **BUGS**\n- **SEE ALSO**\n- **GIT**\n\nUse structuredContent.sections for detailed options, examples, and full documentation.\n"
        }
    ],
    "structuredContent": {
        "command": "git-rm",
        "section": "",
        "mode": "man",
        "summary": "git-rm - Remove files from the working tree and from the index",
        "synopsis": "git rm [-f | --force] [-n] [-r] [--cached] [--ignore-unmatch]\n[--quiet] [--pathspec-from-file=<file> [--pathspec-file-nul]]\n[--] [<pathspec>...]",
        "tldr_summary": "Remove files from repository index and local filesystem.",
        "tldr_examples": [
            {
                "description": "Remove file from repository index and filesystem",
                "command": "git rm {{path/to/file}}"
            },
            {
                "description": "Remove directory [r]ecursively",
                "command": "git rm -r {{path/to/directory}}"
            },
            {
                "description": "Remove file from repository index but keep it untouched locally",
                "command": "git rm --cached {{path/to/file}}"
            },
            {
                "description": "Reduce the repository to only the `.git` directory",
                "command": "git rm -r ."
            }
        ],
        "tldr_source": "official",
        "flags": [
            {
                "flag": "-f",
                "long": "--force",
                "arg": null,
                "description": "Override the up-to-date check."
            },
            {
                "flag": "-n",
                "long": "--dry-run",
                "arg": null,
                "description": "Don’t actually remove any file(s). Instead, just show if they exist in the index and would otherwise be removed by the command."
            },
            {
                "flag": "-r",
                "long": null,
                "arg": null,
                "description": "Allow recursive removal when a leading directory name is given. -- 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)."
            },
            {
                "flag": "",
                "long": "--cached",
                "arg": null,
                "description": "Use this option to unstage and remove paths only from the index. Working tree files, whether modified or not, will be left alone."
            },
            {
                "flag": "",
                "long": "--ignore-unmatch",
                "arg": null,
                "description": "Exit with a zero status even if no files matched."
            },
            {
                "flag": "",
                "long": "--sparse",
                "arg": null,
                "description": "Allow updating index entries outside of the sparse-checkout cone. Normally, git rm refuses to update index entries whose paths do not fit within the sparse-checkout cone. See git-sparse-checkout(1) for more."
            },
            {
                "flag": "-q",
                "long": "--quiet",
                "arg": null,
                "description": "git rm normally outputs one line (in the form of an rm command) for each file removed. This option suppresses that output. --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)."
            }
        ],
        "examples": [
            "git rm Documentation/\\*.txt",
            "Removes all *.txt files from the index that are under the Documentation directory and any",
            "of its subdirectories.",
            "Note that the asterisk * is quoted from the shell in this example; this lets Git, and not",
            "the shell, expand the pathnames of files and subdirectories under the Documentation/",
            "directory.",
            "git rm -f git-*.sh",
            "Because this example lets the shell expand the asterisk (i.e. you are listing the files",
            "explicitly), it does not remove subdir/git-foo.sh."
        ],
        "see_also": [
            {
                "name": "git-add",
                "section": "1",
                "url": "https://www.chedong.com/phpMan.php/man/git-add/1/json"
            }
        ],
        "section_outline": [
            {
                "name": "NAME",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "SYNOPSIS",
                "lines": 5,
                "subsections": []
            },
            {
                "name": "DESCRIPTION",
                "lines": 10,
                "subsections": []
            },
            {
                "name": "OPTIONS",
                "lines": 13,
                "subsections": [
                    {
                        "name": "-f, --force",
                        "lines": 2,
                        "flag": "-f",
                        "long": "--force"
                    },
                    {
                        "name": "-n, --dry-run",
                        "lines": 3,
                        "flag": "-n",
                        "long": "--dry-run"
                    },
                    {
                        "name": "-r",
                        "lines": 6,
                        "flag": "-r"
                    },
                    {
                        "name": "--cached",
                        "lines": 3,
                        "long": "--cached"
                    },
                    {
                        "name": "--ignore-unmatch",
                        "lines": 2,
                        "long": "--ignore-unmatch"
                    },
                    {
                        "name": "--sparse",
                        "lines": 4,
                        "long": "--sparse"
                    },
                    {
                        "name": "-q, --quiet",
                        "lines": 9,
                        "flag": "-q",
                        "long": "--quiet"
                    },
                    {
                        "name": "--pathspec-file-nul",
                        "lines": 3,
                        "long": "--pathspec-file-nul"
                    },
                    {
                        "name": "REMOVING FILES THAT HAVE DISAPPEARED FROM THE FILESYSTEM",
                        "lines": 30
                    },
                    {
                        "name": "Other ways",
                        "lines": 7
                    }
                ]
            },
            {
                "name": "SUBMODULES",
                "lines": 17,
                "subsections": []
            },
            {
                "name": "EXAMPLES",
                "lines": 12,
                "subsections": []
            },
            {
                "name": "BUGS",
                "lines": 6,
                "subsections": []
            },
            {
                "name": "SEE ALSO",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "GIT",
                "lines": 5,
                "subsections": []
            }
        ],
        "sections": {
            "NAME": {
                "content": "git-rm - Remove files from the working tree and from the index\n",
                "subsections": []
            },
            "SYNOPSIS": {
                "content": "git rm [-f | --force] [-n] [-r] [--cached] [--ignore-unmatch]\n[--quiet] [--pathspec-from-file=<file> [--pathspec-file-nul]]\n[--] [<pathspec>...]\n\n",
                "subsections": []
            },
            "DESCRIPTION": {
                "content": "Remove files matching pathspec from the index, or from the working tree and the index. git rm\nwill not remove a file from just your working directory. (There is no option to remove a file\nonly from the working tree and yet keep it in the index; use /bin/rm if you want to do that.)\nThe files being removed have to be identical to the tip of the branch, and no updates to\ntheir contents can be staged in the index, though that default behavior can be overridden\nwith the -f option. When --cached is given, the staged content has to match either the tip of\nthe branch or the file on disk, allowing the file to be removed from just the index. When\nsparse-checkouts are in use (see git-sparse-checkout(1)), git rm will only remove paths\nwithin the sparse-checkout patterns.\n",
                "subsections": []
            },
            "OPTIONS": {
                "content": "<pathspec>...\nFiles to remove. A leading directory name (e.g.  dir to remove dir/file1 and dir/file2)\ncan be given to remove all files in the directory, and recursively all sub-directories,\nbut this requires the -r option to be explicitly given.\n\nThe command removes only the paths that are known to Git.\n\nFile globbing matches across directory boundaries. Thus, given two directories d and d2,\nthere is a difference between using git rm 'd*' and git rm 'd/*', as the former will also\nremove all of directory d2.\n\nFor more details, see the pathspec entry in gitglossary(7).\n",
                "subsections": [
                    {
                        "name": "-f, --force",
                        "content": "Override the up-to-date check.\n",
                        "flag": "-f",
                        "long": "--force"
                    },
                    {
                        "name": "-n, --dry-run",
                        "content": "Don’t actually remove any file(s). Instead, just show if they exist in the index and\nwould otherwise be removed by the command.\n",
                        "flag": "-n",
                        "long": "--dry-run"
                    },
                    {
                        "name": "-r",
                        "content": "Allow recursive removal when a leading directory name is given.\n\n--\nThis option can be used to separate command-line options from the list of files, (useful\nwhen filenames might be mistaken for command-line options).\n",
                        "flag": "-r"
                    },
                    {
                        "name": "--cached",
                        "content": "Use this option to unstage and remove paths only from the index. Working tree files,\nwhether modified or not, will be left alone.\n",
                        "long": "--cached"
                    },
                    {
                        "name": "--ignore-unmatch",
                        "content": "Exit with a zero status even if no files matched.\n",
                        "long": "--ignore-unmatch"
                    },
                    {
                        "name": "--sparse",
                        "content": "Allow updating index entries outside of the sparse-checkout cone. Normally, git rm\nrefuses to update index entries whose paths do not fit within the sparse-checkout cone.\nSee git-sparse-checkout(1) for more.\n",
                        "long": "--sparse"
                    },
                    {
                        "name": "-q, --quiet",
                        "content": "git rm normally outputs one line (in the form of an rm command) for each file removed.\nThis option suppresses that output.\n\n--pathspec-from-file=<file>\nPathspec is passed in <file> instead of commandline args. If <file> is exactly - then\nstandard input is used. Pathspec elements are separated by LF or CR/LF. Pathspec elements\ncan be quoted as explained for the configuration variable core.quotePath (see git-\nconfig(1)). See also --pathspec-file-nul and global --literal-pathspecs.\n",
                        "flag": "-q",
                        "long": "--quiet"
                    },
                    {
                        "name": "--pathspec-file-nul",
                        "content": "Only meaningful with --pathspec-from-file. Pathspec elements are separated with NUL\ncharacter and all other characters are taken literally (including newlines and quotes).\n",
                        "long": "--pathspec-file-nul"
                    },
                    {
                        "name": "REMOVING FILES THAT HAVE DISAPPEARED FROM THE FILESYSTEM",
                        "content": "There is no option for git rm to remove from the index only the paths that have disappeared\nfrom the filesystem. However, depending on the use case, there are several ways that can be\ndone.\n\nUsing ““git commit -a””\nIf you intend that your next commit should record all modifications of tracked files in the\nworking tree and record all removals of files that have been removed from the working tree\nwith rm (as opposed to git rm), use git commit -a, as it will automatically notice and record\nall removals. You can also have a similar effect without committing by using git add -u.\n\nUsing ““git add -A””\nWhen accepting a new code drop for a vendor branch, you probably want to record both the\nremoval of paths and additions of new paths as well as modifications of existing paths.\n\nTypically you would first remove all tracked files from the working tree using this command:\n\ngit ls-files -z | xargs -0 rm -f\n\n\nand then untar the new code in the working tree. Alternately you could rsync the changes into\nthe working tree.\n\nAfter that, the easiest way to record all removals, additions, and modifications in the\nworking tree is:\n\ngit add -A\n\n\nSee git-add(1).\n"
                    },
                    {
                        "name": "Other ways",
                        "content": "If all you really want to do is to remove from the index the files that are no longer present\nin the working tree (perhaps because your working tree is dirty so that you cannot use git\ncommit -a), use the following command:\n\ngit diff --name-only --diff-filter=D -z | xargs -0 git rm --cached\n\n"
                    }
                ]
            },
            "SUBMODULES": {
                "content": "Only submodules using a gitfile (which means they were cloned with a Git version 1.7.8 or\nnewer) will be removed from the work tree, as their repository lives inside the .git\ndirectory of the superproject. If a submodule (or one of those nested inside it) still uses a\n.git directory, git rm will move the submodules git directory into the superprojects git\ndirectory to protect the submodule’s history. If it exists the submodule.<name> section in\nthe gitmodules(5) file will also be removed and that file will be staged (unless --cached or\n-n are used).\n\nA submodule is considered up to date when the HEAD is the same as recorded in the index, no\ntracked files are modified and no untracked files that aren’t ignored are present in the\nsubmodules work tree. Ignored files are deemed expendable and won’t stop a submodule’s work\ntree from being removed.\n\nIf you only want to remove the local checkout of a submodule from your work tree without\ncommitting the removal, use git-submodule(1) deinit instead. Also see gitsubmodules(7) for\ndetails on submodule removal.\n",
                "subsections": []
            },
            "EXAMPLES": {
                "content": "git rm Documentation/\\*.txt\nRemoves all *.txt files from the index that are under the Documentation directory and any\nof its subdirectories.\n\nNote that the asterisk * is quoted from the shell in this example; this lets Git, and not\nthe shell, expand the pathnames of files and subdirectories under the Documentation/\ndirectory.\n\ngit rm -f git-*.sh\nBecause this example lets the shell expand the asterisk (i.e. you are listing the files\nexplicitly), it does not remove subdir/git-foo.sh.\n",
                "subsections": []
            },
            "BUGS": {
                "content": "Each time a superproject update removes a populated submodule (e.g. when switching between\ncommits before and after the removal) a stale submodule checkout will remain in the old\nlocation. Removing the old directory is only safe when it uses a gitfile, as otherwise the\nhistory of the submodule will be deleted too. This step will be obsolete when recursive\nsubmodule update has been implemented.\n",
                "subsections": []
            },
            "SEE ALSO": {
                "content": "git-add(1)\n",
                "subsections": []
            },
            "GIT": {
                "content": "Part of the git(1) suite\n\n\n\nGit 2.34.1                                   02/26/2026                                    GIT-RM(1)",
                "subsections": []
            }
        }
    }
}