Removing a Git submodule

When working with Git submodules, there's no simple equivalent to git submodule add to remove a submodule you no longer need. Removing submodules requires a little bit of manual editing and a couple of commands to achieve:

  1. Run git submodule deinit --all
  2. Delete the submodule from the .gitmodules files. It should look something along the lines of:
     [submodule "module"]
         path = contrib/module
         url =
  1. Stage your .gitmodules file by running git add .gitmodules.
  2. Run git rm --cached path/to/submodule to remove the files associated with the submodule from the index
  3. Finally, remove the module from git's index by running rm -rf .git/modules/[module name].

That's all there's to it - you're now free to delete the files associated with the submodule. After a commit, the submodule will no longer be part of the repository.

Hope this helps!