I have in a folder a large number of projects that I cloned for quite some time; recently I moved this whole folder into one of my repos and would like to convert these cloned p
I will add onto @neevek's answer, if you get the already exists in the index
error, then you can try this version:
Remove every "already cloned repository" from cache:
(Because there is already an object there that does not point to the repository as a submodule, and it has to be deleted from index first to prevent conflict. Your repositories' contents or index will not be deleted upon doing this)
git rm --cached ./localrepo
Use git submodule add https//example.com/remoterepo ./localrepo
, where ./localrepo
is your existing git repository.
remoterepo
from localrepo/.git/config
.git submodule foreach git pull
to update all your subprojects.If you have lots of submodules, you may want to write a small script to automate the second step.