Skip to content

Instantly share code, notes, and snippets.

@kyleturner
Created January 5, 2012 01:07
Show Gist options
  • Save kyleturner/1563153 to your computer and use it in GitHub Desktop.
Save kyleturner/1563153 to your computer and use it in GitHub Desktop.
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.
@AJFaraday
Copy link

Thanks! This was really handy.

@vtourraine
Copy link

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

@afiskon
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
Copy link

+1 @afiskon
Can the gist be updated?

@kranthitech
Copy link

+1 @afiskon 's solution is working

@matanox
Copy link

matanox commented Oct 29, 2015

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

@renatomefi
Copy link

+1 for update

@rrrhys
Copy link

rrrhys commented Nov 3, 2015

@joshmun23
Copy link

+1

@flaccid
Copy link

flaccid commented Nov 20, 2015

Copy link

ghost commented Nov 27, 2015

+1

Copy link

ghost commented Dec 19, 2015

+1

@oodzchen
Copy link

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
Copy link

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
Copy link

Yep still on google! Thanks

@rico
Copy link

rico commented Mar 14, 2016

+1

@erenkabakci
Copy link

+1

@draconteus
Copy link

+1

@adipascu
Copy link

Why doesn't the git team make this simpler?

@Flimm
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
Copy link

+1

@noinfo
Copy link

noinfo commented Mar 2, 2017

+1

@nickarnold
Copy link

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

@YuehChuan
Copy link

useful!

@GordonSmith
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

@pranavavva
Copy link

nice +1

@pranavavva
Copy link

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

@fcambarieri
Copy link

@kikeelectronico
Copy link

+1

@siyuhong
Copy link

siyuhong commented Nov 3, 2022

git rm -- .gitmodules [ModulesName]

eg.
git rm -- .gitmodules QtSsh

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment