我需要使用ssh forwarding-agent在远程服务器上启用git克隆。存储库有子模块,最初添加了https
地址。为了使转发代理工作,我想我需要将这些地址更改为相应的ssh
地址。
在.git/config
中更改这些地址会解决我的问题吗?
使用git config --global url.<base>.insteadOf
即时替换URL。就像是
git config --global url.<new-url-with-https>.insteadOf git@<server>:<user>/<repo>.git
查看https://stackoverflow.com/search?q=%5Bgit-submodules%5D+insteadof中的更多示例
模块的URL存储在沙箱根目录的.gitmodules
中。此文件作为Git存储库的一部分进行跟踪。如果你在这里进行更改并提交它,那么Git repo的其他用户就可以看到它。
当您调用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
文件夹。