How do I remove a submodule?

R. Martinho Fernandes picture R. Martinho Fernandes · Aug 11, 2009 · Viewed 934.5k times · Source

How do I remove a Git submodule?

By the way, is there a reason I can't simply do git submodule rm whatever ?

Answer

John Douthat picture John Douthat · Aug 11, 2009

Via the page Git Submodule Tutorial:

To remove a submodule you need to:

  1. Delete the relevant section from the .gitmodules file.
  2. Stage the .gitmodules changes:
    git add .gitmodules
  3. Delete the relevant section from .git/config.
  4. Remove the submodule files from the working tree and index:
    git rm --cached path_to_submodule (no trailing slash).
  5. Remove the submodule's .git directory:
    rm -rf .git/modules/path_to_submodule
  6. Commit the changes:
    git commit -m "Removed submodule <name>"
  7. Delete the now untracked submodule files:
    rm -rf path_to_submodule

See also: alternative steps below.