How to completely remove git submodules within a repository

I found myself having to google this multiple times so I decide to write it here as a quick references for myself.

Git submodules is a way for you to keep a git repository as a subdirectory of another git repository. It’s useful when you want to incorporate and keep track of external code or framework that your project depends on. It’s like a poor man’s version of npm or cocoapods.

Anyway, to add a git submodules is very easy. It’s just simple a one liner. Eg:

1git submodule add library/example-submodule

That’s it. But the steps to remove it are very tedious and it’s something that I always forgot how to. So here are the steps to completely remove it from your repository.

To Completely Remove Git Submodule

  1. Open and edit the .gitmodules with your text editor.
  2. Find and delete the relevant submodule lines:
    1[submodule "library/example-submodule"]
    2    path = library/example-submodule
    3    url =
  3. Open and edit .git/config file.
  4. Find and delete the relevant submodule lines:
    1[submodule "library/example-submodule"]
    2 url =
  5. Delete the submodules.
    1$~ rm -rf library/example-submodule
  6. Delete the files in .git/modules
    1$~ rm -rf .git/modules/example-submodule
  7. Now, there should be some unstaged changes in your git staging area. Stage it and commit all the changes.

That should be it. Maybe you can turn this into a one liner bash script.

Until next time. ✌️