DEV Community

William L'Archeveque
William L'Archeveque

Posted on

How to effectively and completely delete a git submodule

I have been working on multiple projects included as Git submodules in a parent repository. Recently, I had to remove one project that we did not need anymore.

Side note : This parent repository is used to easily clone multiple projects in the same directory for new employees at our startup. The different projects are linked together and interact to each other as their code is executed in separate Docker containers.

Example project structure :

|- blog_main
    |- blog_api
    |- blog_frontend
    |- local_dev_infrastructure
Enter fullscreen mode Exit fullscreen mode

Here is the way I could remove a submodule and commit the changes to the parent directory.

git submodule deinit <path_to_submodule>
git rm <path_to_submodule>
git commit -m "Removed submodule"
rm -rf .git/modules/<path_to_submodule>
Enter fullscreen mode Exit fullscreen mode

Top comments (0)