一次添加多个 Git 子模块的最简单方法?

Easiest way to add multiple Git submodules at once?

我有一组 Git 个子模块要包含在多个项目中。我使用 TortoiseGit 并且将它们一个一个地添加到每个新项目中并不方便。

例如,在 TortoiseSVN 中,可以简单地将 svn:externals 导出到一个文件,然后将该文件应用到一个新项目中。我正在寻找类似的东西(如果可能的话,我宁愿避免编写脚本)。

在这种情况下我最好的选择是什么?

基本上,TortoiseGit 添加子模块对话框只是 git submodule add which basically is just a wrapper for the file .gitmodules 工作树根目录中的一个 GUI 前端。

也就是说,你可以考虑自动调用 git submodule add 或只是手写一个 .gitmodules (或从另一个存储库复制它)然后需要注册子模块(这不能是使用 TortoiseGit ATM 完成):

git config -f .gitmodules --get-regexp '^submodule\..*\.path$' |
    while read path_key path
    do
        url_key=$(echo $path_key | sed 's/\.path/.url/')
        url=$(git config -f .gitmodules --get "$url_key")
        git submodule add $url $path
done

基于:https://gist.github.com/aroemen/5027030