How to remove Git submodules


Here’s a simple guide on how to remove Git submodules. Lets say I want to remove a Git submodule called drafts.

  1. Edit .gitmodules to remove lines that are similar to the example below.
    [submodule "drafts"]
      path = drafts
      url = git://github.com/emcorrales/drafts.git
    
  2. Stage the .gitmodules file.
    git add .gitmodules
    
  3. Remove the submodule from the git index. Ensure that there is no trailing slash. We’re deleting the reference to the submodule and not the directory.
    git rm --cached drafts
    
  4. Remove the untracked files left by the submodule.
    rm -rf drafts
    
  5. Commit changes.
    git commit -m "Remove draft submodule.".
    
  6. There are still references to the drafts submodule. Edit .git/config and remove lines that are similar to the example below.
    [submodule "drafts"]
      url = git://github.com/emcorrales/drafts.git
    
  7. Remove the copy of the submodule’s git repo.
    rm -rf .git/modules/drafts
    

    There you have it, you have succesfully removed the submodule from your local git repo.