How to add already cloned projects as submodules?

后端 未结 3 499
[愿得一人]
[愿得一人] 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:34

    To add many submodules, I wrote this simple loop:

    for repo in vim/bundle/*
    do
      echo $repo
      pushd $repo
      url=$(git remote get-url $(git remote))
      echo $url
      popd
      git submodule add $url ./$repo
    done
    

    Obvious limitations I didn't bother fixing:

    • don't need to change directory, pretty sure you can pass the git directory as an argument to commands
    • git remote actually returns all remotes, not just the current, so script will break if there are multiple

提交回复
热议问题