Remove Git Submodule

September 23, 2019

Have you ever tried Git submodule for your project? And then you found that it’s annoying to build CI/CD with it?
Instead of using Git submodule, it’s better to create the submodule as NPM package.

Here is how to remove Git submodule from project:

# Remove the submodule entry from .git/config
git submodule deinit -f path/to/submodule

# Remove the submodule directory from the superproject's .git/modules directory
rm -rf .git/modules/path/to/submodule

# Remove the entry in .gitmodules and remove the submodule directory located at path/to/submodule
git rm -f path/to/submodule


Manual and cleaner way:

  • Delete the section referring to the submodule from the .gitmodules file
  • Stage the changes via git add .gitmodules
  • Delete the relevant section of the submodule from .git/config.
  • Run git rm --cached path_to_submodule (no trailing slash)
  • Run rm -rf .git/modules/path_to_submodule
  • Commit the changes with “`git commit -m “Removed submodule “
  • Delete the now untracked submodule files rm -rf path_to_submodule