Git 从现有的 repos 中将子模块添加到 super 项目

标签 git bash batch-file cross-platform git-submodules

我在一个目录中有几个(大约 10-15 个)Git 存储库:

~/plugins/admin
~/plugins/editor
~/plugins/etc

每个都有自己独立的存储库和远程服务器。

问题是要从所有存储库中提取所有更改,我必须:

cd ~/plugins/admin
git pull origin master
password: ********
cd ..

cd ~/plugins/editor
git pull origin master
password: ********
cd ..

cd ~/plugins/etc
git pull origin master
password: ********
cd ..

我如何设置 Git 子模块以使用 1 个命令 pull 所有存储库,

或者为 Windows、Linux 和 Mac(因为我使用所有 3 个操作系统)编写一个脚本来有效地做同样的事情。请记住,存储库可以位于不同的分支上,并且不一定具有跟踪分支设置。

同样的注释:

  • 密码对所有的repos都是一样的
  • 远程服务器是同一个仓库(显然在单独的仓库/目录中)
  • 我只想输入一次密码
  • 我只想键入一个命令来 pull 所有 repos
  • 公钥/私钥不是一个选项
  • 我正在通过 ssh 连接到远程

最佳答案

bash-3.2$ git submodule add git@repoUrl:SubmoduleName.git existing/submodule/path
Adding existing repo at 'existing/submodule/path' to the index

当你试图从已经存在一些 git repo 的地方添加子模块时,这个 repo 将被添加到索引中。

关于Git 从现有的 repos 中将子模块添加到 super 项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3727976/

相关文章:

windows - 如何将linux批处理文件转换为windows bat文件?

git - 如何从 fork 中 check out PR?

linux - 有效的赋值运算符 Bash

bash - 使用ssh列出远程服务器上文件的md5sum并以文本文件形式返回输出?

bash - 打印时为每一行添加前缀以使用 tee 输出

windows - 从 ipconfig 获取 MAC 和 DHCP 服务器

windows - 如何在后台从命令行启动 GUI 应用程序?

node.js - 跟踪程序中的内部版本号和版本

git - 如何在 azure devops 中设置默认分支策略

git - 通过 "sneakernet"复制 git 存储库