A coworker asked me a question this evening about how to move a Git submodule to a sub-directory, and as it’s something I’ve had to look up multiple times in the past, I decided it would be good to post it here for easy lookup in the future.

How to move a Git submodule to a sub-directory Link to heading

  1. Delete the submodule reference from .gitmodules (normally 3 lines)
  2. Check .git/config for references to the submodule and remove them, if they exist
  3. Run git rm --cached <submodule name> to remove the submodule reference from the repository
  4. Remove the old submodule folder
  5. Recreate your submodule reference with git submodule add <git repo url> <local path>

I’m publishing this as part of 100 Days To Offload (Day 20/100). You can join in yourself by visiting https://100DaysToOffload.com.