Last Updated: June 01, 2022
·
208
· Amar Sanakal

Deleting a git submodule

Sometimes you find yourself in a situation where you realise that a submodule that you had added to your git repo is no longer needed. Since it's rarely done, one has to go about looking up the documentation every time to see how it's done. In my experience, I've also had to do it in more than 1 commit because I did not do everything needed in one go. So here's all the steps that are needed.

$ git submodule deinit <path_to_submodule>
$ vi .gitmodules # delete the section for the submodule to delete
$ git add .gitmodules
$ git rm <path_to_submodule>
$ git commit -m "submodule deleted"

The final step does not impact any new clone but needed only to clean up your current one

$ rm -rf .git/modules/<path_to_submodule>