How to remove a Submodule from your Git repository

Posted May 15th, 2021 • 1 min read

In this short post I'll share how to do just that.

We all know having submodules in Git is very handy. You don't have to check all of the code in, just the reference and, when needed, initialize them.

Traces of submodules

When installing a submodule in Git it does a couple of things. It adds a record to your .gitmodules file. When this file doesn't exist it will create one. An example of this is:

[submodule "some/nice/folder"]
    path = some/nice/folder
    url = git://

Secondly, it adds the URLs/mappings to your .git/config file. This is done when you use git init submodule.

Last but not least, it adds references to the submodule in your commits.

Fine, but how do I get rid of them?

The first two traces are easy enough to remove. Just open up .gitmodules and remove the reference to it. Next, open up .git/config and remove the mappings there as well. Last, but not least, use the following command from the root directory of your git repository:

$ git rm --cached path/to/submodule

Notice that you have to leave out the trailing slash, else the command will moan about it.

And that's it! Your submodule is gone.

Hope this helps anyone.

More posts

May 15th, 2021 • 11 min read
Today I want to show a generic workflow and setup I have used a lot lately when working on building apps with Angular. It uses Gulp as a CI system and Browserify to minimize code clutter and maximize awesomeness.
May 15th, 2021 • 3 min read
I heard a lot about SASS, mostly a lot of people raving about how it was the best thing since chocolate.
May 15th, 2021 • 1 min read
It's good practice to force either www or non-www for your website. But how do you redirect your traffic properly using Express?