ade's notes

Remove a Submodule from a Git Repo

Doing a simple git rm <path-to-submodule> doesn’t actually fully remove a submodule; it leaves a submodule directory at .git/modules/<path-to-submodule>, and a section in the .gitmodules file.

So here’s a script to completely remove a submodule from a git repo. Note that it assumes that the submodule is at ./<path-to-submodule> relative to the root of the git repository. You will have to adjust this if it is at a different path.

git rm <path-to-submodule> || echo
rm -rf .git/modules/<path-to-submodule>
git config --remove-section submodule.<path-to-submodule>

This script is adapted from a How do I remove a submodule? question on Stack Overflow.

See Also