Remove a git submodule from your repository



  • Since I have been playing with Hugo, I also have started using git submodule, as that is the recommended way to add a theme.

    Adding is easy enough, but how do you clean up your git repo once you have added a half dozen themes for testing things out?

    Well it is 5 commands.

    git submodule deinit <submodule_path>
    git rm <submodule_path>
    git commit-m "Submodule removed"
    rm -rf .git/modules/<submodule_path>
    git push
    

    Here is a full example. Assuming you are in the base folder of the hugo site.
    in my case cd ~/repos/jaredbusch.com

    git submodule deinit themes/hugo-tikva/
    git rm themes/hugo-tikva/
    git commit-m "Submodule removed"
    rm -rf .git/modules/themes/hugo-tikva/
    git push