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
- Delete the submodule reference from
.gitmodules(normally 3 lines)
.git/configfor references to the submodule and remove them, if they exist
git rm --cached <submodule name>to remove the submodule reference from the repository
- Remove the old submodule folder
- 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.