These are the steps required to replace a directory with a submodule in git. Note: Assumes that you are currently working on branch called 'develop'
- Check out a new branch to make the changes on:
git checkout -b creating-submodule
- delete directory to be replaced
rm -rf path/of/directory/to/be/replaced
git add .
thengit commit -m "removing local directory"
- add the submodule:
git submodule add "https://github.com/repoName" path/of/directory/to/be/replaced
git add .
thengit commit -m "adding submodule"
- delete the submodule directory if you don't do this git will throw a hissy when you try to checkout out develop to merge the changes in
git checkout develop
- pull the submodule back into the local repo:
git submodule foreach git fetch --tags
thengit submodule update --init --recursive
git push
I found that in git version 2.24.3, after step 5 I only needed to
git push
.