How to add already cloned projects as submodules?

后端 未结 3 467
[愿得一人]
[愿得一人] 2021-02-08 07:00

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

3条回答
  •  面向向阳花
    2021-02-08 07:17

    I will add onto @neevek's answer, if you get the already exists in the index error, then you can try this version:

    1. 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
      
    2. Use git submodule add https//example.com/remoterepo ./localrepo, where ./localrepo is your existing git repository.

      • Note: You get the URL for remoterepo from localrepo/.git/config.
    3. Repeat the second step for all your existing repositories that you want to add as submodules.
    4. Now you can run 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.

提交回复
热议问题