Skip to content

Instantly share code, notes, and snippets.

Created November 3, 2014 17:36
Show Gist options
  • Save myusuf3/7f645819ded92bda6677 to your computer and use it in GitHub Desktop.
Save myusuf3/7f645819ded92bda6677 to your computer and use it in GitHub Desktop.
How effectively delete a git submodule.

To remove a submodule you need to:

  • Delete the relevant section from the .gitmodules file.
  • Stage the .gitmodules changes git add .gitmodules
  • Delete the relevant section from .git/config.
  • Run git rm --cached path_to_submodule (no trailing slash).
  • Run rm -rf .git/modules/path_to_submodule (no trailing slash).
  • Commit git commit -m "Removed submodule "
  • Delete the now untracked submodule files rm -rf path_to_submodule
Copy link

thank you so much

Copy link

Thank you!

Copy link

If you're doing this a lot, you can create an executable script discoverable in your PATH named git-submodule-remove with the following contents:

Then you can run git submodule-remove path/to/submodule to quickly remove it and play uno online card game
Good response, Thank's man.

Copy link

Thank you

Copy link

andrp92 commented Oct 5, 2023

I was using this gist for a while. It was really helpful!

However, deleting a submodule it’s a lot easier nowadays. Latest GitHub versions allows you to run: git rm <path_to_submodule> and git takes care of it. Afterwards you just need to commit the changes and that’s it.

I hope this helps.

Copy link

Got an error from the "git rm --cached path_to_submodule" part. (something about sparse checkout)

Fixed it by running this intead:
"git update-index --remove path_to_submodule"

Copy link


Copy link


Copy link

MeronGit commented Feb 1, 2024

Seemed to work well :)

Copy link

Suggestion: we can run command git config -f .gitmodules --remove-section "submodule.<submodule_name>"

Copy link

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