Remove a Submodule

Remove a Submodule

Removing a submodule is not a single command — it requires three cleanup steps to fully clear the submodule from your repository.

Steps

$ git submodule deinit <path>       # 1. unregister from .git/config
$ git rm <path>                     # 2. remove from working tree and index
$ rm -rf .git/modules/<path>        # 3. delete cached clone
$ git commit -m "Remove submodule"

What each step does

  1. deinit — removes the submodule entry from .git/config and clears the working directory at <path>. The submodule’s URL remains in .gitmodules until the next step removes it.
  2. git rm — removes the submodule entry from .gitmodules and from the index (staging area). Also deletes the working directory if deinit did not already.
  3. rm -rf .git/modules/<path> — deletes the cached bare clone that Git keeps under .git/modules/. Without this step, re-adding a submodule at the same path can use stale data.

Common gotchas

For other submodule operations, see the Submodules recipe.

On this page