Ok, so we all know that having git submodules to include libraries in a git project is very handy. Today, I was trying to remove a git submodule that I had in a project, and couldn’t really a find a good answer by googling, so I went in irc and thanks to a good samaritan: Ilari, I found the answer.
Let’s say that you have a submodule in your project called ’submodule1′ and it’s in the following path: ‘vendors/submodule1′. In git there are 3 traces of this this submodule:
1) .gitmodules
2) .git/config
3) the submodule entry in the index/commit itself.
To remove the first two, is really simple, you just edit those files and remove the lines that specify the submdoule. In order to delete the third and last trace of the submodule in git, you need to type the following command:
git rm --cached path/to/submodule
Note: Do not put a trailing slash at the end of path. If you put a trailing slash at the end of the command, it will fail.
In the example above, we would type (do not include trailing slash after submodule1):
git rm --cached vendors/submodule1
Finding this information in google is not easy, hopefully this will help other git users.
Comments (25)
Thanks,
It was really very helpful.
Akhil
doesn’t work for me:
fatal: pathspec ‘vendor/plugins/will_paginate/’ did not match any files
Akhil – I’m glad it was helpful. I was surprised that finding the answer to a simple question was not available in the docs
Kain – I created a smal scratch repo with a submodule, and after I typed the git rm –cached path/to/submodule command, the submodule is staged to be deleted in the index. You need to use “git commit” to commit the deletion of the submodule as well as the .gitmodules file.
If you are getting the error when you type the git rm –cached command that means that your submodule is not tracked in the index itself. Check with git-status, and see if that submodule is set for deletion. If it isn’t, something went wrong while you were setting up your submodule.
kain:
git rm –cached path/to/submodule/
won’t work
git rm –cached path/to/submodule
this works.
Thanks a million for this post. Hopefully this feature will be added to this git core sometime soon.
Thanks very much — worked for me.
I was looking for an answer to this issue too, but in my experiments only *git rm* seems to be mandatory, if i understood right .gitmodules is some kind of database to keep track of the relation [ module path, git uri ], same for .git/config, you dont need to update them manually. Also *git rm* only remove the module from the git repository database, the files will persist unless you manually delete them.
Please correct me if im wrong.
You just saved the rest of my hair!
Thanks for a great tip.
I wonder why doesn’t Git include a command to remove a submodule. Something similar to git submodule add.
Anyone knows a reason why this doesn’t exists?
Thanks,
made my day.
Thank you! I have been to visit this page a few times. It is very helpful. I always search for ‘git remove submodule’ and find myself here.
“Finding this information in google is not easy, hopefully this will help other git users.”
I totally disagree, when I google it, I came to this page…hehehe..,Thanks man!
Hi,
Thanks for the tip, very handy.
Cheers,
Rafael.
from a casual git-user
thank you, oh thank you
Phew… thanks for this post. Was googling around a little bit and finding some very off topic stuff.
That is a useful tip. Thanks.
Unfortunately, I still have a trace of a removed submodule: git submodule summary still shows remnants of its existence. Any ideas?
Jose, can you please remove the last comment that exposes the email. Thanks.
I removed the email from your last comment before it was approved.
thanks to you, it is now easy to find on google.
thanks
I’ve come back to this twice already! Thank you.
You’re a life saver. I’ve been dealing with a stubborn submodule for over an hour. This worked perfectly. Thanks for sharing.
Ya put a smile in my face.
cheers very helpful thanx
Exactly what i was looking for. Thank you, worked like a charm!
Trackbacks/Pingbacks (5)
[...] isn’t a command to remove submodules from Git. If you need to remove them follow this post: http://pitupepito.homelinux.org/?p=24 NOTE: When doing ‘git rm –cached path/to/submodule’ do NOT include a trailing [...]
[...] Encontré la respuesta que transcribo a continuación en éste artículo [...]
[...] How to remove a git submodule < Flop’s Scribbles One way (?) to remove submodules in Git. (tags: git remove submodule) The Links for 2008-12-21 article by Aral Balkan, unless otherwise expressly stated, is licensed under a Creative Commons Attribution-Noncommercial 2.0 UK: England License. [...]
[...] submodule rm Came across Jose Cedeon’s blog post about how to remove a git submodule. Very [...]
[...] How to remove a git submodule < Flop’s Scribbles (tags: programming tutorial development tips git submodule) Подобни постове:links for 2008-09-06links for 2009-05-17links for 2008-09-10links for 2008-09-07links for 2008-08-29 [...]