tags:

views:

721

answers:

2

The title says it all: how do I remove a git submodule?

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

+4  A: 

You must remove the entry in .gitmodules and remove the directory of the module from the history:

git rm --cached path/to/submodule

If you'll write on git's mailing list probably someone will do a shell script for you.

Carmine Paolino
That doesn't work. When I run `git submodule` after that, I get an error saying there is no submodule mapping in `.gitmodules`.
Martinho Fernandes
Figured it out. The directory must be removed from the history. Clarified and accepted your answer.
Martinho Fernandes
thanks for the clarification
Carmine Paolino
+10  A: 

(via this page)

To remove a submodule you need to:

  1. Delete the relevant line from the .gitmodules file.
  2. Delete the relevant section from .git/config.
  3. Run git rm --cached path_to_submodule (no trailing slash).
  4. Commit and delete the now untracked submodule files.
John Douthat