How to remove a Submodule from your Git repository

Posted May 26th, 2011 • 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://github.com/your_idol/awesome.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.

Stay up to date

Want to know when a new post comes out and stay in the loop on tips, tricks and gotchas? Consider signing up for the Mindthecode newsletter.

Comments

Keep reading

May 9th, 2012 • 4 min read
How to format an associative array in JSON with Knockout
October 12th, 2017 • 8 min read
I have been a big fan of the .vue files, but I wanted to use them in a traditional non-SPA site. Luckily, you can!
May 22nd, 2011 • 4 min read
The following setup can work nicely when you develop your sites locally and don't want to change the configuration every time you upload it.