CINXE.COM
Git - git-rm Documentation
<!DOCTYPE html> <html lang="en"> <head> <script type="text/javascript"> const currentTheme = localStorage.getItem("theme") if (currentTheme) { const prefersDarkScheme = window.matchMedia("(prefers-color-scheme: dark)").matches if ((prefersDarkScheme && currentTheme === "light") || (!prefersDarkScheme && currentTheme === "dark")) { document.documentElement.dataset.theme = currentTheme } } </script> <meta charset='utf-8'> <meta content='IE=edge,chrome=1' http-equiv='X-UA-Compatible'> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>Git - git-rm Documentation</title> <link href="/favicon.ico" rel='shortcut icon' type='image/x-icon'> <link rel="stylesheet" href="/application.min.css"> </head> <body id="documentation"> <div class="inner"> <header> <a id="logo" href="/"><img src="/images/logo@2x.png" width="110" height="46" alt="Git" class="no-filter" /></a> <span id="tagline"></span> <script type="text/javascript"> const taglines = [ "fast-version-control", "everything-is-local", "distributed-even-if-your-workflow-isnt", "local-branching-on-the-cheap", "distributed-is-the-new-centralized" ]; var tagline = taglines[Math.floor(Math.random() * taglines.length)]; document.getElementById('tagline').innerHTML = '--' + tagline; </script> <div id="search-container"> <form id="search" action="/search/results"> <input id="search-text" name="search" placeholder="Type / to search entire site…" autocomplete="off" type="text" /> </form> <div id="search-results"></div> </div> <img src="/images/dark-mode.svg" id="dark-mode-button" /> </header> </div> <div class="inner"> <div id="content-wrapper"> <div tabindex="1" class="sidebar-btn"></div> <aside class="sidebar" id="sidebar"> <nav> <ul> <li> <a href="/about">About</a> <ul> </ul> </li> <li> <a href="/doc" class="active">Documentation</a> <ul class="expanded"> <li> <a href="/docs" class="active">Reference</a> </li> <li> <a href="/book">Book</a> </li> <li> <a href="/videos">Videos</a> </li> <li> <a href="/doc/ext">External Links</a> </li> </ul> </li> <li> <a href="/downloads">Downloads</a> <ul > <li> <a href="/downloads/guis">GUI Clients</a> </li> <li> <a href="/downloads/logos">Logos</a> </li> </ul> </li> <li> <a href="/community">Community</a> </li> </ul> </nav> </aside> <div id="content"> <div id='reference-version'> <a class="dropdown-trigger" id="reference-languages-trigger" data-panel-id="l10n-versions-dropdown" href="#"> English ▾</a> <div class='dropdown-panel right' id='l10n-versions-dropdown'> <header>Localized versions of <strong>git-rm</strong> manual</header> <ol class='reference-previous-versions'> <li> <a href="/docs/git-rm"><span class="version">English</span> </a> </li> <li> <a href="/docs/git-rm/fr"><span class="version">Français</span> </a> </li> <li> <a href="/docs/git-rm/pt_BR"><span class="version">Português (Brasil)</span> </a> </li> <li> <a href="/docs/git-rm/zh_HANS-CN"><span class="version">简体中文</span> </a> </li> </ol> <footer> Want to read in your language or fix typos?<br/> <a href="https://github.com/jnavila/git-manpages-l10n">You can help translate this page</a>. </footer> </div> <a class="dropdown-trigger" id="reference-topics-trigger" data-panel-id="topics-dropdown" href="#">Topics ▾</a> <div class='dropdown-panel right' id='topics-dropdown'> <div class='three-column'> <div class='column-left'> <h3 class='setup'>Setup and Config</h3> <ul class='unstyled'> <li> <a href="/docs/git"> git </a> </li> <li> <a href="/docs/git-config"> config </a> </li> <li> <a href="/docs/git-help"> help </a> </li> <li> <a href="/docs/git-bugreport"> bugreport </a> </li> <li> <a href="/doc/credential-helpers"> Credential helpers </a> </li> </ul> <h3 class='projects'>Getting and Creating Projects</h3> <ul class='unstyled'> <li> <a href="/docs/git-init"> init </a> </li> <li> <a href="/docs/git-clone"> clone </a> </li> </ul> <h3 class='snapshotting'>Basic Snapshotting</h3> <ul class='unstyled'> <li> <a href="/docs/git-add"> add </a> </li> <li> <a href="/docs/git-status"> status </a> </li> <li> <a href="/docs/git-diff"> diff </a> </li> <li> <a href="/docs/git-commit"> commit </a> </li> <li> <a href="/docs/git-notes"> notes </a> </li> <li> <a href="/docs/git-restore"> restore </a> </li> <li> <a href="/docs/git-reset"> reset </a> </li> <li> <a href="/docs/git-rm"> rm </a> </li> <li> <a href="/docs/git-mv"> mv </a> </li> </ul> <h3 class='branching'>Branching and Merging</h3> <ul class='unstyled'> <li> <a href="/docs/git-branch"> branch </a> </li> <li> <a href="/docs/git-checkout"> checkout </a> </li> <li> <a href="/docs/git-switch"> switch </a> </li> <li> <a href="/docs/git-merge"> merge </a> </li> <li> <a href="/docs/git-mergetool"> mergetool </a> </li> <li> <a href="/docs/git-log"> log </a> </li> <li> <a href="/docs/git-stash"> stash </a> </li> <li> <a href="/docs/git-tag"> tag </a> </li> <li> <a href="/docs/git-worktree"> worktree </a> </li> </ul> <h3 class='sharing'>Sharing and Updating Projects</h3> <ul class='unstyled'> <li> <a href="/docs/git-fetch"> fetch </a> </li> <li> <a href="/docs/git-pull"> pull </a> </li> <li> <a href="/docs/git-push"> push </a> </li> <li> <a href="/docs/git-remote"> remote </a> </li> <li> <a href="/docs/git-submodule"> submodule </a> </li> </ul> </div> <div class='column-middle'> <h3 class='inspection'>Inspection and Comparison</h3> <ul class='unstyled'> <li> <a href="/docs/git-show"> show </a> </li> <li> <a href="/docs/git-log"> log </a> </li> <li> <a href="/docs/git-diff"> diff </a> </li> <li> <a href="/docs/git-difftool"> difftool </a> </li> <li> <a href="/docs/git-range-diff"> range-diff </a> </li> <li> <a href="/docs/git-shortlog"> shortlog </a> </li> <li> <a href="/docs/git-describe"> describe </a> </li> </ul> <h3 class='patching'>Patching</h3> <ul class='unstyled'> <li> <a href="/docs/git-apply"> apply </a> </li> <li> <a href="/docs/git-cherry-pick"> cherry-pick </a> </li> <li> <a href="/docs/git-diff"> diff </a> </li> <li> <a href="/docs/git-rebase"> rebase </a> </li> <li> <a href="/docs/git-revert"> revert </a> </li> </ul> <h3 class='debugging'>Debugging</h3> <ul class='unstyled'> <li> <a href="/docs/git-bisect"> bisect </a> </li> <li> <a href="/docs/git-blame"> blame </a> </li> <li> <a href="/docs/git-grep"> grep </a> </li> </ul> <h3 class='email'>Email</h3> <ul class='unstyled'> <li> <a href="/docs/git-am"> am </a> </li> <li> <a href="/docs/git-apply"> apply </a> </li> <li> <a href="/docs/git-format-patch"> format-patch </a> </li> <li> <a href="/docs/git-send-email"> send-email </a> </li> <li> <a href="/docs/git-request-pull"> request-pull </a> </li> </ul> <h3 class='external'>External Systems</h3> <ul class='unstyled'> <li> <a href="/docs/git-svn"> svn </a> </li> <li> <a href="/docs/git-fast-import"> fast-import </a> </li> </ul> <h3 class='server-admin'>Server Admin</h3> <ul class='unstyled'> <li> <a href="/docs/git-daemon"> daemon </a> </li> <li> <a href="/docs/git-update-server-info"> update-server-info </a> </li> </ul> </div> <div class='column-right'> <h3 class='guides'>Guides</h3> <ul class='unstyled'> <li> <a href="/docs/gitattributes"> gitattributes </a> </li> <li> <a href="/docs/gitcli"> Command-line interface conventions </a> </li> <li> <a href="/docs/giteveryday"> Everyday Git </a> </li> <li> <a href="/docs/gitfaq"> Frequently Asked Questions (FAQ) </a> </li> <li> <a href="/docs/gitglossary"> Glossary </a> </li> <li> <a href="/docs/githooks"> Hooks </a> </li> <li> <a href="/docs/gitignore"> gitignore </a> </li> <li> <a href="/docs/gitmodules"> gitmodules </a> </li> <li> <a href="/docs/gitrevisions"> Revisions </a> </li> <li> <a href="/docs/gitsubmodules"> Submodules </a> </li> <li> <a href="/docs/gittutorial"> Tutorial </a> </li> <li> <a href="/docs/gitworkflows"> Workflows </a> </li> <li> <a href="/docs/git#_guides"> All guides... </a> </li> </ul> <h3 class='admin'>Administration</h3> <ul class='unstyled'> <li> <a href="/docs/git-clean"> clean </a> </li> <li> <a href="/docs/git-gc"> gc </a> </li> <li> <a href="/docs/git-fsck"> fsck </a> </li> <li> <a href="/docs/git-reflog"> reflog </a> </li> <li> <a href="/docs/git-filter-branch"> filter-branch </a> </li> <li> <a href="/docs/git-instaweb"> instaweb </a> </li> <li> <a href="/docs/git-archive"> archive </a> </li> <li> <a href="/docs/git-bundle"> bundle </a> </li> </ul> <h3 class='plumbing'>Plumbing Commands</h3> <ul class='unstyled'> <li> <a href="/docs/git-cat-file"> cat-file </a> </li> <li> <a href="/docs/git-check-ignore"> check-ignore </a> </li> <li> <a href="/docs/git-checkout-index"> checkout-index </a> </li> <li> <a href="/docs/git-commit-tree"> commit-tree </a> </li> <li> <a href="/docs/git-count-objects"> count-objects </a> </li> <li> <a href="/docs/git-diff-index"> diff-index </a> </li> <li> <a href="/docs/git-for-each-ref"> for-each-ref </a> </li> <li> <a href="/docs/git-hash-object"> hash-object </a> </li> <li> <a href="/docs/git-ls-files"> ls-files </a> </li> <li> <a href="/docs/git-ls-tree"> ls-tree </a> </li> <li> <a href="/docs/git-merge-base"> merge-base </a> </li> <li> <a href="/docs/git-read-tree"> read-tree </a> </li> <li> <a href="/docs/git-rev-list"> rev-list </a> </li> <li> <a href="/docs/git-rev-parse"> rev-parse </a> </li> <li> <a href="/docs/git-show-ref"> show-ref </a> </li> <li> <a href="/docs/git-symbolic-ref"> symbolic-ref </a> </li> <li> <a href="/docs/git-update-index"> update-index </a> </li> <li> <a href="/docs/git-update-ref"> update-ref </a> </li> <li> <a href="/docs/git-verify-pack"> verify-pack </a> </li> <li> <a href="/docs/git-write-tree"> write-tree </a> </li> </ul> </div> </div> </div> <a class="dropdown-trigger" id="reference-versions-trigger" data-panel-id="previous-versions-dropdown" href="#"> Latest version ▾ </a> <span class="light d-flex">git-rm last updated in 2.43.0</span> <div class='dropdown-panel left' id='previous-versions-dropdown'> <header>Changes in the <strong>git-rm</strong> manual</header> <ol class='reference-previous-versions'> <li class="no-change"><span>2.43.1 → 2.49.0 no changes</span></li> <li> <a href="/docs/git-rm/2.43.0"><span class="version">2.43.0</span> <span class="diff"> <img src="/images/icons/green-dot.png" /> <img src="/images/icons/red-dot.png" /> <img src="/images/icons/grey-dot.png" /> <img src="/images/icons/grey-dot.png" /> <img src="/images/icons/grey-dot.png" /> <img src="/images/icons/grey-dot.png" /> <img src="/images/icons/grey-dot.png" /> <img src="/images/icons/grey-dot.png" /> </span> <em class="date">2023-11-20</em> </a> </li> <li class="no-change"><span>2.34.1 → 2.42.4 no changes</span></li> <li> <a href="/docs/git-rm/2.34.0"><span class="version">2.34.0</span> <span class="diff"> <img src="/images/icons/green-dot.png" /> <img src="/images/icons/green-dot.png" /> <img src="/images/icons/green-dot.png" /> <img src="/images/icons/green-dot.png" /> <img src="/images/icons/green-dot.png" /> <img src="/images/icons/green-dot.png" /> <img src="/images/icons/red-dot.png" /> <img src="/images/icons/red-dot.png" /> <img src="/images/icons/grey-dot.png" /> <img src="/images/icons/grey-dot.png" /> </span> <em class="date">2021-11-15</em> </a> </li> <li class="no-change"><span>2.32.1 → 2.33.8 no changes</span></li> <li> <a href="/docs/git-rm/2.32.0"><span class="version">2.32.0</span> <span class="diff"> <img src="/images/icons/green-dot.png" /> <img src="/images/icons/green-dot.png" /> <img src="/images/icons/green-dot.png" /> <img src="/images/icons/red-dot.png" /> <img src="/images/icons/grey-dot.png" /> <img src="/images/icons/grey-dot.png" /> <img src="/images/icons/grey-dot.png" /> <img src="/images/icons/grey-dot.png" /> </span> <em class="date">2021-06-06</em> </a> </li> <li class="no-change"><span>2.26.1 → 2.31.8 no changes</span></li> <li> <a href="/docs/git-rm/2.26.0"><span class="version">2.26.0</span> <span class="diff"> <img src="/images/icons/green-dot.png" /> <img src="/images/icons/green-dot.png" /> <img src="/images/icons/green-dot.png" /> <img src="/images/icons/green-dot.png" /> <img src="/images/icons/red-dot.png" /> <img src="/images/icons/red-dot.png" /> <img src="/images/icons/red-dot.png" /> <img src="/images/icons/red-dot.png" /> <img src="/images/icons/grey-dot.png" /> <img src="/images/icons/grey-dot.png" /> </span> <em class="date">2020-03-22</em> </a> </li> <li class="no-change"><span>2.16.6 → 2.25.5 no changes</span></li> <li> <a href="/docs/git-rm/2.15.4"><span class="version">2.15.4</span> <span class="diff"> <img src="/images/icons/green-dot.png" /> <img src="/images/icons/red-dot.png" /> <img src="/images/icons/grey-dot.png" /> <img src="/images/icons/grey-dot.png" /> <img src="/images/icons/grey-dot.png" /> <img src="/images/icons/grey-dot.png" /> <img src="/images/icons/grey-dot.png" /> <img src="/images/icons/grey-dot.png" /> </span> <em class="date">2019-12-06</em> </a> </li> <li> <a href="/docs/git-rm/2.14.6"><span class="version">2.14.6</span> <span class="diff"> <img src="/images/icons/green-dot.png" /> <img src="/images/icons/green-dot.png" /> <img src="/images/icons/red-dot.png" /> <img src="/images/icons/red-dot.png" /> <img src="/images/icons/grey-dot.png" /> <img src="/images/icons/grey-dot.png" /> <img src="/images/icons/grey-dot.png" /> <img src="/images/icons/grey-dot.png" /> </span> <em class="date">2019-12-06</em> </a> </li> <li> <a href="/docs/git-rm/2.13.7"><span class="version">2.13.7</span> <span class="diff"> <img src="/images/icons/green-dot.png" /> <img src="/images/icons/green-dot.png" /> <img src="/images/icons/green-dot.png" /> <img src="/images/icons/green-dot.png" /> <img src="/images/icons/red-dot.png" /> <img src="/images/icons/red-dot.png" /> <img src="/images/icons/red-dot.png" /> <img src="/images/icons/red-dot.png" /> <img src="/images/icons/grey-dot.png" /> <img src="/images/icons/grey-dot.png" /> </span> <em class="date">2018-05-22</em> </a> </li> <li class="no-change"><span>2.1.4 → 2.12.5 no changes</span></li> <li> <a href="/docs/git-rm/2.0.5"><span class="version">2.0.5</span> <span class="diff"> <img src="/images/icons/green-dot.png" /> <img src="/images/icons/green-dot.png" /> <img src="/images/icons/green-dot.png" /> <img src="/images/icons/green-dot.png" /> <img src="/images/icons/green-dot.png" /> <img src="/images/icons/green-dot.png" /> <img src="/images/icons/green-dot.png" /> <img src="/images/icons/green-dot.png" /> <img src="/images/icons/red-dot.png" /> <img src="/images/icons/red-dot.png" /> <img src="/images/icons/grey-dot.png" /> <img src="/images/icons/grey-dot.png" /> </span> <em class="date">2014-12-17</em> </a> </li> <li> </li> </ol> <footer> <p>Check your version of git by running</p> <code class="command">git --version</code> </footer> </div> </div> <div id="main" data-pagefind-filter="category:reference" data-pagefind-meta="category:Reference" data-pagefind-weight="0.05" data-pagefind-body> <div class="sect1"> <h2 id="_name"><a class="anchor" href="#_name"></a>NAME</h2> <div class="sectionbody"> <div class="paragraph"> <p>git-rm - Remove files from the working tree and from the index</p> </div> </div> </div> <div class="sect1"> <h2 id="_synopsis"><a class="anchor" href="#_synopsis"></a>SYNOPSIS</h2> <div class="sectionbody"> <div class="verseblock"> <pre class="content"><em>git rm</em> [-f | --force] [-n] [-r] [--cached] [--ignore-unmatch] [--quiet] [--pathspec-from-file=<file> [--pathspec-file-nul]] [--] [<pathspec>…​]</pre> </div> </div> </div> <div class="sect1"> <h2 id="_description"><a class="anchor" href="#_description"></a>DESCRIPTION</h2> <div class="sectionbody"> <div class="paragraph"> <p>Remove files matching pathspec from the index, or from the working tree and the index. <code>git rm</code> will not remove a file from just your working directory. (There is no option to remove a file only from the working tree and yet keep it in the index; use <code>/bin/rm</code> if you want to do that.) The files being removed have to be identical to the tip of the branch, and no updates to their contents can be staged in the index, though that default behavior can be overridden with the <code>-f</code> option. When <code>--cached</code> is given, the staged content has to match either the tip of the branch or the file on disk, allowing the file to be removed from just the index. When sparse-checkouts are in use (see <a href='/docs/git-sparse-checkout'>git-sparse-checkout[1]</a>), <code>git rm</code> will only remove paths within the sparse-checkout patterns.</p> </div> </div> </div> <div class="sect1"> <h2 id="_options"><a class="anchor" href="#_options"></a>OPTIONS</h2> <div class="sectionbody"> <div class="dlist"> <dl> <dt class="hdlist1" id="Documentation/git-rm.txt-ltpathspecgt82308203"> <a class="anchor" href="#Documentation/git-rm.txt-ltpathspecgt82308203"></a><pathspec>…​ </dt> <dd> <p>Files to remove. A leading directory name (e.g. <code>dir</code> to remove <code>dir/file1</code> and <code>dir/file2</code>) can be given to remove all files in the directory, and recursively all sub-directories, but this requires the <code>-r</code> option to be explicitly given.</p> <div class="paragraph"> <p>The command removes only the paths that are known to Git.</p> </div> <div class="paragraph"> <p>File globbing matches across directory boundaries. Thus, given two directories <code>d</code> and <code>d2</code>, there is a difference between using <code>git rm 'd*'</code> and <code>git rm 'd/*'</code>, as the former will also remove all of directory <code>d2</code>.</p> </div> <div class="paragraph"> <p>For more details, see the <em>pathspec</em> entry in <a href='/docs/gitglossary'>gitglossary[7]</a>.</p> </div> </dd> <dt class="hdlist1" id="Documentation/git-rm.txt--f"> <a class="anchor" href="#Documentation/git-rm.txt--f"></a>-f </dt> <dt class="hdlist1" id="Documentation/git-rm.txt---force"> <a class="anchor" href="#Documentation/git-rm.txt---force"></a>--force </dt> <dd> <p>Override the up-to-date check.</p> </dd> <dt class="hdlist1" id="Documentation/git-rm.txt--n"> <a class="anchor" href="#Documentation/git-rm.txt--n"></a>-n </dt> <dt class="hdlist1" id="Documentation/git-rm.txt---dry-run"> <a class="anchor" href="#Documentation/git-rm.txt---dry-run"></a>--dry-run </dt> <dd> <p>Don’t actually remove any file(s). Instead, just show if they exist in the index and would otherwise be removed by the command.</p> </dd> <dt class="hdlist1" id="Documentation/git-rm.txt--r"> <a class="anchor" href="#Documentation/git-rm.txt--r"></a>-r </dt> <dd> <p>Allow recursive removal when a leading directory name is given.</p> </dd> <dt class="hdlist1" id="Documentation/git-rm.txt---"> <a class="anchor" href="#Documentation/git-rm.txt---"></a>-- </dt> <dd> <p>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).</p> </dd> <dt class="hdlist1" id="Documentation/git-rm.txt---cached"> <a class="anchor" href="#Documentation/git-rm.txt---cached"></a>--cached </dt> <dd> <p>Use this option to unstage and remove paths only from the index. Working tree files, whether modified or not, will be left alone.</p> </dd> <dt class="hdlist1" id="Documentation/git-rm.txt---ignore-unmatch"> <a class="anchor" href="#Documentation/git-rm.txt---ignore-unmatch"></a>--ignore-unmatch </dt> <dd> <p>Exit with a zero status even if no files matched.</p> </dd> <dt class="hdlist1" id="Documentation/git-rm.txt---sparse"> <a class="anchor" href="#Documentation/git-rm.txt---sparse"></a>--sparse </dt> <dd> <p>Allow updating index entries outside of the sparse-checkout cone. Normally, <code>git rm</code> refuses to update index entries whose paths do not fit within the sparse-checkout cone. See <a href='/docs/git-sparse-checkout'>git-sparse-checkout[1]</a> for more.</p> </dd> <dt class="hdlist1" id="Documentation/git-rm.txt--q"> <a class="anchor" href="#Documentation/git-rm.txt--q"></a>-q </dt> <dt class="hdlist1" id="Documentation/git-rm.txt---quiet"> <a class="anchor" href="#Documentation/git-rm.txt---quiet"></a>--quiet </dt> <dd> <p><code>git rm</code> normally outputs one line (in the form of an <code>rm</code> command) for each file removed. This option suppresses that output.</p> </dd> <dt class="hdlist1" id="Documentation/git-rm.txt---pathspec-from-fileltfilegt"> <a class="anchor" href="#Documentation/git-rm.txt---pathspec-from-fileltfilegt"></a>--pathspec-from-file=<file> </dt> <dd> <p>Pathspec is passed in <code><file></code> instead of commandline args. If <code><file></code> is exactly <code>-</code> 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 <code>core.quotePath</code> (see <a href='/docs/git-config'>git-config[1]</a>). See also <code>--pathspec-file-nul</code> and global <code>--literal-pathspecs</code>.</p> </dd> <dt class="hdlist1" id="Documentation/git-rm.txt---pathspec-file-nul"> <a class="anchor" href="#Documentation/git-rm.txt---pathspec-file-nul"></a>--pathspec-file-nul </dt> <dd> <p>Only meaningful with <code>--pathspec-from-file</code>. Pathspec elements are separated with NUL character and all other characters are taken literally (including newlines and quotes).</p> </dd> </dl> </div> </div> </div> <div class="sect1"> <h2 id="_removing_files_that_have_disappeared_from_the_filesystem"><a class="anchor" href="#_removing_files_that_have_disappeared_from_the_filesystem"></a>REMOVING FILES THAT HAVE DISAPPEARED FROM THE FILESYSTEM</h2> <div class="sectionbody"> <div class="paragraph"> <p>There is no option for <code>git rm</code> to remove from the index only the paths that have disappeared from the filesystem. However, depending on the use case, there are several ways that can be done.</p> </div> <div class="sect2"> <h3 id="_using_git_commit_a"><a class="anchor" href="#_using_git_commit_a"></a>Using “git commit -a”</h3> <div class="paragraph"> <p>If you intend that your next commit should record all modifications of tracked files in the working tree and record all removals of files that have been removed from the working tree with <code>rm</code> (as opposed to <code>git rm</code>), use <code>git commit -a</code>, as it will automatically notice and record all removals. You can also have a similar effect without committing by using <code>git add -u</code>.</p> </div> </div> <div class="sect2"> <h3 id="_using_git_add_a"><a class="anchor" href="#_using_git_add_a"></a>Using “git add -A”</h3> <div class="paragraph"> <p>When accepting a new code drop for a vendor branch, you probably want to record both the removal of paths and additions of new paths as well as modifications of existing paths.</p> </div> <div class="paragraph"> <p>Typically you would first remove all tracked files from the working tree using this command:</p> </div> <div class="listingblock"> <div class="content"> <pre>git ls-files -z | xargs -0 rm -f</pre> </div> </div> <div class="paragraph"> <p>and then untar the new code in the working tree. Alternately you could <em>rsync</em> the changes into the working tree.</p> </div> <div class="paragraph"> <p>After that, the easiest way to record all removals, additions, and modifications in the working tree is:</p> </div> <div class="listingblock"> <div class="content"> <pre>git add -A</pre> </div> </div> <div class="paragraph"> <p>See <a href='/docs/git-add'>git-add[1]</a>.</p> </div> </div> <div class="sect2"> <h3 id="_other_ways"><a class="anchor" href="#_other_ways"></a>Other ways</h3> <div class="paragraph"> <p>If all you really want to do is to remove from the index the files that are no longer present in the working tree (perhaps because your working tree is dirty so that you cannot use <code>git commit -a</code>), use the following command:</p> </div> <div class="listingblock"> <div class="content"> <pre>git diff --name-only --diff-filter=D -z | xargs -0 git rm --cached</pre> </div> </div> </div> </div> </div> <div class="sect1"> <h2 id="_submodules"><a class="anchor" href="#_submodules"></a>SUBMODULES</h2> <div class="sectionbody"> <div class="paragraph"> <p>Only submodules using a gitfile (which means they were cloned with a Git version 1.7.8 or newer) will be removed from the work tree, as their repository lives inside the .git directory of the superproject. If a submodule (or one of those nested inside it) still uses a .git directory, <code>git rm</code> will move the submodules git directory into the superprojects git directory to protect the submodule’s history. If it exists the submodule.<name> section in the <a href='/docs/gitmodules'>gitmodules[5]</a> file will also be removed and that file will be staged (unless --cached or -n are used).</p> </div> <div class="paragraph"> <p>A submodule is considered up to date when the HEAD is the same as recorded in the index, no tracked files are modified and no untracked files that aren’t ignored are present in the submodule’s work tree. Ignored files are deemed expendable and won’t stop a submodule’s work tree from being removed.</p> </div> <div class="paragraph"> <p>If you only want to remove the local checkout of a submodule from your work tree without committing the removal, use <a href='/docs/git-submodule'>git-submodule[1]</a> <code>deinit</code> instead. Also see <a href='/docs/gitsubmodules'>gitsubmodules[7]</a> for details on submodule removal.</p> </div> </div> </div> <div class="sect1"> <h2 id="_examples"><a class="anchor" href="#_examples"></a>EXAMPLES</h2> <div class="sectionbody"> <div class="dlist"> <dl> <dt class="hdlist1" id="Documentation/git-rm.txt-codegitrmDocumentationtxtcode"> <a class="anchor" href="#Documentation/git-rm.txt-codegitrmDocumentationtxtcode"></a><code>git rm Documentation/\*.txt</code> </dt> <dd> <p>Removes all <code>*.txt</code> files from the index that are under the <code>Documentation</code> directory and any of its subdirectories.</p> <div class="paragraph"> <p>Note that the asterisk <code>*</code> is quoted from the shell in this example; this lets Git, and not the shell, expand the pathnames of files and subdirectories under the <code>Documentation/</code> directory.</p> </div> </dd> <dt class="hdlist1" id="Documentation/git-rm.txt-codegitrm-fgit-shcode"> <a class="anchor" href="#Documentation/git-rm.txt-codegitrm-fgit-shcode"></a><code>git rm -f git-*.sh</code> </dt> <dd> <p>Because this example lets the shell expand the asterisk (i.e. you are listing the files explicitly), it does not remove <code>subdir/git-foo.sh</code>.</p> </dd> </dl> </div> </div> </div> <div class="sect1"> <h2 id="_bugs"><a class="anchor" href="#_bugs"></a>BUGS</h2> <div class="sectionbody"> <div class="paragraph"> <p>Each time a superproject update removes a populated submodule (e.g. when switching between commits before and after the removal) a stale submodule checkout will remain in the old location. Removing the old directory is only safe when it uses a gitfile, as otherwise the history of the submodule will be deleted too. This step will be obsolete when recursive submodule update has been implemented.</p> </div> </div> </div> <div class="sect1"> <h2 id="_see_also"><a class="anchor" href="#_see_also"></a>SEE ALSO</h2> <div class="sectionbody"> <div class="paragraph"> <p><a href='/docs/git-add'>git-add[1]</a></p> </div> </div> </div> <div class="sect1"> <h2 id="_git"><a class="anchor" href="#_git"></a>GIT</h2> <div class="sectionbody"> <div class="paragraph"> <p>Part of the <a href='/docs/git'>git[1]</a> suite</p> </div> </div> </div> <h3 hidden="true" data-pagefind-weight="10">rm</h3> </div> </div> </div> <footer> <div class="site-source"> <a href="/site">About this site</a><br> Patches, suggestions, and comments are welcome. </div> <div class="sfc-member"> Git is a member of <a href="/sfc">Software Freedom Conservancy</a> </div> </footer> <a href="#top" class="no-js scrollToTop" id="scrollToTop" data-label="Scroll to top"> <img src="/images/icons/chevron-up@2x.png" width="20" height="20" alt="scroll-to-top"/> </a> <script src="/js/jquery-1.7.1.min.js"></script> <script src="/js/jquery-ui-1.8.18.custom.min.js"></script> <script src="/js/jquery.defaultvalue.js"></script> <script src="/js/session.min.js"></script> <script src="/js/modernizr.js"></script> <script src="/js/modernize.js"></script> <script src="/js/application.min.js"></script> </div> </body> </html>