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

August 6th, 2013 • 2 min read
Let me show you how you can get syntax highlighted output from cat in the terminal
May 16th, 2012 • 3 min read
With this little gem you can watch specific folders or file extensions and run commands based on the files you watch.
May 5th, 2014 • 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.