我需要使用ssh forwarding-agent在远程服务器上启用git克隆。该存储库包含最初添加了其https
地址的子模块。为了使转发代理正常工作,我认为我需要将那些地址更改为它们对应的ssh
地址。
更改.git/config
中的这些地址是否可以解决我的问题?
答案 0 :(得分:3)
使用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
中查看更多示例答案 1 :(得分:0)
模块的URL存储在沙箱根目录的.gitmodules
中。该文件将作为Git存储库的一部分进行跟踪。如果您在此处进行更改并提交更改,那么Git存储库的其他用户将可以看到该更改。
当您依次呼叫git submodule sync
和git submodule init
时,URL被解析并复制到.git/config
。调用git submodule update
时,将克隆子模块,并且在.git/modules/<module-name>/config
中也可以找到其URL。
要永久更改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,该URL是子模块的.git
文件夹。