将 .git/config 中子模块的 https 地址更改为 ssh-address
Changing https-address of submodules in .git/config to ssh-address
我需要使用 ssh forwarding-agent 在远程服务器上启用 git 克隆。存储库有子模块,这些子模块最初是用它们的 https
地址添加的。为了让转发代理工作,我想我需要将这些地址更改为它们对应的 ssh
地址。
更改 .git/config
中的这些地址可以解决我的问题吗?
模块的 URL 存储在沙箱根目录下的 .gitmodules
中。此文件作为 Git 存储库的一部分进行跟踪。如果您在此处进行更改并提交,Git 存储库的其他用户将可以看到它。
当您调用 git submodule sync
然后调用 git submodule init
时,URL 被解析并复制到 .git/config
。当您调用 git submodule update
时,子模块被克隆并且它的 URL 也在 .git/modules/<module-name>/config
.
中找到
要永久更改 URL,请编辑 .gitmodules
并再次调用 git submodule sync
和 git submodule init
。
要临时更改 URL,请改为进行以下两项更改:
为子模块.git/config
更改URL
进入子模块并调用:
git remote set-url origin <new-url-with-https>
第二个命令将更新 .git/modules/<module-name>/config
中的 URL,这是子模块的 .git
文件夹。
编辑:如果模块和子模块都在同一台服务器上,对子模块使用相对 URLs 将一劳永逸地解决问题:每个沙箱将使用相同的协议获取子模块主要回购被克隆。另见:
使用 git config --global url.<base>.insteadOf
即时替换 URL。像
git config --global url.<new-url-with-https>.insteadOf git@<server>:<user>/<repo>.git
在https://whosebug.com/search?q=%5Bgit-submodules%5D+insteadof
中查看更多示例
最近,github 弃用了 git://
协议,我想更新我存储库中的子模块以使用 https://
而不是 git://
。
我做了以下事情:
$ vim .gitmodules # Change all the git:// URLs into https:// URLs
$ git submodule init
$ git add .gitmodules
$ git commit -m "Update submodules"
$ git push origin main
您可以将 URL 转换为 ssh://
。
我需要使用 ssh forwarding-agent 在远程服务器上启用 git 克隆。存储库有子模块,这些子模块最初是用它们的 https
地址添加的。为了让转发代理工作,我想我需要将这些地址更改为它们对应的 ssh
地址。
更改 .git/config
中的这些地址可以解决我的问题吗?
模块的 URL 存储在沙箱根目录下的 .gitmodules
中。此文件作为 Git 存储库的一部分进行跟踪。如果您在此处进行更改并提交,Git 存储库的其他用户将可以看到它。
当您调用 git submodule sync
然后调用 git submodule init
时,URL 被解析并复制到 .git/config
。当您调用 git submodule update
时,子模块被克隆并且它的 URL 也在 .git/modules/<module-name>/config
.
要永久更改 URL,请编辑 .gitmodules
并再次调用 git submodule sync
和 git submodule init
。
要临时更改 URL,请改为进行以下两项更改:
为子模块.git/config
更改URL
进入子模块并调用:
git remote set-url origin <new-url-with-https>
第二个命令将更新 .git/modules/<module-name>/config
中的 URL,这是子模块的 .git
文件夹。
编辑:如果模块和子模块都在同一台服务器上,对子模块使用相对 URLs 将一劳永逸地解决问题:每个沙箱将使用相同的协议获取子模块主要回购被克隆。另见:
使用 git config --global url.<base>.insteadOf
即时替换 URL。像
git config --global url.<new-url-with-https>.insteadOf git@<server>:<user>/<repo>.git
在https://whosebug.com/search?q=%5Bgit-submodules%5D+insteadof
中查看更多示例最近,github 弃用了 git://
协议,我想更新我存储库中的子模块以使用 https://
而不是 git://
。
我做了以下事情:
$ vim .gitmodules # Change all the git:// URLs into https:// URLs
$ git submodule init
$ git add .gitmodules
$ git commit -m "Update submodules"
$ git push origin main
您可以将 URL 转换为 ssh://
。