How to delete a git submodule

I am confused to why the git submodule command is not symmetrical. The command supports adding a submodule, but it doesn’t have a delete submodule command. Why? The argument for “preventing deleting changes” in the stack overflow post is not very convincing. Nevertheless, I found it useful to know how to delete a submodule, so I am just pasting John Douthat / philfreo’s answer here:


To remove a submodule you need to:

  1. Delete the relevant line from the .gitmodules file.
  2. Delete the relevant section from .git/config.
  3. Run git rm --cached path_to_submodule (no trailing slash).
  4. Commit and delete the now untracked submodule files.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: