How you can effectively delete a git submodule

Every now and then you need to delete a Git submodule. Since you don't do this often, you quickly forget how to do it. Here is a short tutorial for the next time.

  1. Delete the relevant section in .gitmodules
  2. Stage the .gitmodules changes with git add .gitmodules
  3. Delete the relevant section from .git/config
  4. Run git rm --cached path_to_submodule (no trailing slash)
  5. Run rm -rf .git/modules/path_to_submodule (no trailing slash)
  6. Commit git commit -m "Removed submodule"
  7. Delete the now untracked submodule files with rm -rf path_to_submodule