How to remove Git submodules
11 Oct 2019Here’s a simple guide on how to remove Git submodules. Lets say I want to remove a Git submodule called drafts.
- Edit .gitmodules to remove lines that are similar to the example below.
[submodule "drafts"] path = drafts url = git://github.com/emcorrales/drafts.git
- Stage the .gitmodules file.
git add .gitmodules
- Remove the submodule from the git index. Ensure that there is no trailing slash. We’re deleting the reference to the submodule and not the directory.
git rm --cached drafts
- Remove the untracked files left by the submodule.
rm -rf drafts
- Commit changes.
git commit -m "Remove draft submodule.".
- There are still references to the drafts submodule. Edit .git/config and remove lines that are similar to the example below.
[submodule "drafts"] url = git://github.com/emcorrales/drafts.git
- Remove the copy of the submodule’s git repo.
rm -rf .git/modules/drafts
There you have it, you have succesfully removed the submodule from your local git repo.