This page looks best with JavaScript enabled

Remove Git Submodule

 ·  ☕ 1 min read

What are Submodule?

Git submodule represents a record in a host git repository pointing to a particular commit in another external repository. The file of the .gitmodule includes meta data on how to map amid the URL of the submodule project and local directory.

Remove a submodule

Follow the steps

  • 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
  • Commit git commit -m "Removed submodule <name>"
  • Delete the now untracked submodule files rm -rf path_to_submodule
#!/bin/sh

SM=$1

git submodule deinit $SM
git rm --cached $SM
rm -rf $SM
rm -rf .git/modules/$SM