How to remove a Git submodule

Git submodules are a very powerful way to add libraries to your project. They are easy to add but there is no easy way to remove them.
I recently needed to remove one submodule from one of my project and run in some pitfalls to avoid here are my findings:

If you for example need to remove a submodule called SELibrary in your main git repository folder, do the following:

  • Open a terminal shell in you main git repository folder
  • Edit the .gitmodule file and find and remove these three lines from it:
    [submodule "SELibrary"]
    path = SELibrary
    url =
  • Remove these two lines from .git/config
    [submodule "SELibrary"]
    url =
  • Delete the git reference file that holds the submodule’s SHA commit id. Note the important lack of a trailing slash.
    git rm --cached SELibrary
  • Git will now see the entire directory as new files, because it’s no longer a submodule. Now you are free to delete the whole lot.
    rm -rf SELibrary/

If you ever need to do a move of a submodule remove it and then add the submodule in the new location.

By Sérgio Estêvão

Hello my name is Sérgio and I’m an experienced Mobile Software Architect living in Edinburgh.

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