[英]Changing https-address of submodules in .git/config to ssh-address
I need to use ssh forwarding-agent to enable git cloning on remote servers.我需要使用 ssh 转发代理在远程服务器上启用 git 克隆。 The repository has submodules which were originally added with their
https
addresses.存储库具有子模块,这些子模块最初是用它们的
https
地址添加的。 In order for forwarding agent to work, I think I need to change those addresses to their corresponding ssh
address.为了让货运代理工作,我想我需要将这些地址更改为相应的
ssh
地址。
Will changing these addresses in .git/config
solve my problem?更改
.git/config
中的这些地址会解决我的问题吗?
Use git config --global url.<base>.insteadOf
to substitute URLs on the fly. 使用
git config --global url.<base>.insteadOf
可以即时替换URL。 Something like 就像是
git config --global url.<new-url-with-https>.insteadOf git@<server>:<user>/<repo>.git
See more examples in https://stackoverflow.com/search?q=%5Bgit-submodules%5D+insteadof 请参阅https://stackoverflow.com/search?q=%5Bgit-submodules%5D+insteadof中的更多示例
The URL of the module is stored in .gitmodules
at the root of your sandbox. 模块的URL存储在沙
.gitmodules
目录下的.gitmodules
中。 This file is tracked as part of the Git repository. 该文件将作为Git存储库的一部分进行跟踪。 If you make the change here and commit it, it will be visible to other users of the Git repo.
如果您在此处进行更改并提交更改,那么Git存储库的其他用户将可以看到该更改。
When you call git submodule sync
and then git submodule init
, the URL is resolved and copied to .git/config
. 当您调用
git submodule sync
并随后调用git submodule sync
git submodule init
,URL被解析并复制到.git/config
。 When you call git submodule update
, the submodule is cloned and its URL is also found in .git/modules/<module-name>/config
. 当您调用
git submodule update
,将克隆该子模块,并且还可以在.git/modules/<module-name>/config
找到其URL。
To permanently change the URL, edit .gitmodules
and call git submodule sync
and git submodule init
again. 要永久更改URL,请编辑
.gitmodules
并再次调用git submodule sync
和git submodule init
。
To temporarily change the URL, make these two changes instead: 要临时更改URL,请进行以下两项更改:
Change the URL in .git/config
for the submodule 更改
.git/config
模块的URL
Go inside the submodule and call: 进入子模块并调用:
git remote set-url origin <new-url-with-https>
The second command will update the URL in .git/modules/<module-name>/config
which is the .git
folder for the submodule. 第二个命令将更新
.git/modules/<module-name>/config
中的URL,该URL是子模块的.git
文件夹。
Recently, github deprecated usage of git://
protocol and I wanted to update the submodules in my repository to use https://
instead of git://
.最近,github 弃用了
git://
协议,我想更新我存储库中的子模块以使用https://
而不是git://
。
I did the following:我做了以下事情:
$ 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
You can do the same to convert URLs to ssh://
.您可以执行相同操作以将 URL 转换为
ssh://
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.