Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
How to remove a submodule from a Github project
To remove a submodule you need to:
Delete the relevant line from the .gitmodules file.
Delete the relevant section from .git/config.
Run git rm --cached path_to_submodule (no trailing slash).
Commit and delete the now untracked submodule files.
@renatoch

This comment has been minimized.

Copy link

renatoch commented Jul 3, 2014

Helped a lot, thanks!
To remove all submodules, you can run:
git config --remove-section submodule."Complete submodule name"

@joe1chen

This comment has been minimized.

Copy link

joe1chen commented Aug 14, 2014

I also had to remove .git/modules/<submodule name> directory in order to be completely rid of the submodule. Otherwise I kept on getting the error A git directory for '<submodule name>' is found locally with remote(s) when trying to re-add the submodule with same name but from different forked repository.

@jfmercer

This comment has been minimized.

Copy link

jfmercer commented Aug 13, 2015

Congratulations. Your gist made it to the top of Google's search results.

image

@westover

This comment has been minimized.

Copy link

westover commented Aug 13, 2015

+1 to @joe1chen I had to do that also

@AJFaraday

This comment has been minimized.

Copy link

AJFaraday commented Aug 26, 2015

Thanks! This was really handy.

@vtourraine

This comment has been minimized.

Copy link

vtourraine commented Sep 8, 2015

Small correction: “Delete the relevant lines from the .gitmodules file.” (multiple lines, even for one submodule).

@afiskon

This comment has been minimized.

Copy link

afiskon commented Sep 8, 2015

This instruction doesn't quite work, at least with Git 1.9.1. The following order seems to be right (source):

  • Run git rm --cached <submodule name>
  • Delete the relevant lines from the .gitmodules file.
  • Delete the relevant section from .git/config.
  • Commit
  • Delete the now untracked submodule files.
  • Remove directory .git/modules/<submodule name>
@hansbogert

This comment has been minimized.

Copy link

hansbogert commented Oct 3, 2015

+1 @afiskon
Can the gist be updated?

@kranthitech

This comment has been minimized.

Copy link

kranthitech commented Oct 16, 2015

+1 @afiskon 's solution is working

@matanster

This comment has been minimized.

Copy link

matanster commented Oct 29, 2015

Still can't believe this isn't superseded by a simple git feature.

@renatomefi

This comment has been minimized.

Copy link

renatomefi commented Nov 2, 2015

+1 for update

@rrrhys

This comment has been minimized.

Copy link

rrrhys commented Nov 3, 2015

@joshmun23

This comment has been minimized.

Copy link

joshmun23 commented Nov 3, 2015

+1

@flaccid

This comment has been minimized.

Copy link

flaccid commented Nov 20, 2015

@ghost

This comment has been minimized.

Copy link

ghost commented Nov 27, 2015

+1

@ghost

This comment has been minimized.

Copy link

ghost commented Dec 19, 2015

+1

@oodzchen

This comment has been minimized.

Copy link

oodzchen commented Dec 21, 2015

Thanks a lot, I'm from google too, and I did it successfully.

Don't forget run git add --all before git rm --cached path_to_submodule

@craigfurman

This comment has been minimized.

Copy link

craigfurman commented Jan 6, 2016

You don't need to manually prune the submodule from .git/config if you run git submodule deinit <path-to-submodule> first. I was using git 2.6.3.

@lfrodrigues

This comment has been minimized.

Copy link

lfrodrigues commented Jan 21, 2016

Yep still on google! Thanks

@rico

This comment has been minimized.

Copy link

rico commented Mar 14, 2016

+1

@erenkabakci

This comment has been minimized.

Copy link

erenkabakci commented Apr 6, 2016

+1

@draconteus

This comment has been minimized.

Copy link

draconteus commented Apr 10, 2016

+1

@adipascu

This comment has been minimized.

Copy link

adipascu commented Apr 14, 2016

Why doesn't the git team make this simpler?

@Flimm

This comment has been minimized.

Copy link

Flimm commented Apr 18, 2016

To delete the relevant section from .git/config, you can also run:

 git submodule deinit <submodule_name>
@marcuslang

This comment has been minimized.

Copy link

marcuslang commented Aug 16, 2016

+1

@noinfo

This comment has been minimized.

Copy link

noinfo commented Mar 2, 2017

+1

@nickarnold

This comment has been minimized.

Copy link

nickarnold commented Jul 6, 2017

I also found that I needed to delete the relevant file/folder under .git/modules/<mySubmodule>.

@YuehChuan

This comment has been minimized.

Copy link

YuehChuan commented Sep 8, 2017

useful!

@GordonSmith

This comment has been minimized.

Copy link

GordonSmith commented Oct 23, 2017

According to the git submodule deinit documents it should be a simple matter of:

git rm path/to/submodule

Seemed to work for me?

"If you really want to remove a submodule from the repository and commit that use git-rm[1] instead. See gitsubmodules[7] for removal options." - https://git-scm.com/docs/git-submodule#git-submodule-deinit-f--force--all--ltpathgt82308203

@20avva

This comment has been minimized.

Copy link

20avva commented Nov 13, 2017

nice +1

@20avva

This comment has been minimized.

Copy link

20avva commented Nov 13, 2017

@jfmercer only 2nd on Bing's index because bing sucks

@fcambarieri

This comment has been minimized.

Copy link

fcambarieri commented Jan 17, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.