[英]How to use git with ssh on github https repository addresses?
I want to clone some github repositories to computers that have only access to github via an SSH tunnel. 我想将一些github存储库克隆到只能通过SSH隧道访问github的计算机。
I can use the ssh addresses to clone simple repositories without problems. 我可以使用ssh地址克隆简单的存储库而不会出现问题。
When a repository contains submodules, the access method is controled by .gitsubmodules
which often default to https addresses (since this is the recommended way by github). 当存储库包含子模块时,访问方法由.gitsubmodules
控制,通常默认为https地址(因为这是github推荐的方式)。
Is there a way to tell git submodules that it should always use ssh access, even when the address of a submodule is an https address? 有没有办法告诉git子模块它应该总是使用ssh访问,即使子模块的地址是https地址?
Having to clone a repo and modify its .gitsubmodules
just to be able to clone it through an ssh tunnel seems retarded. 必须克隆一个repo并修改它的.gitsubmodules
只是为了能够通过ssh隧道克隆它似乎是迟钝的。 Hardcoding the access method in a .gitsubmodules
file instead of letting your users choose the appropiate method seems pretty retarded too. 在.gitsubmodules
文件中对访问方法进行.gitsubmodules
而不是让用户选择适当的方法似乎也相当迟钝。 I guess there must be a better way but I cannot find it. 我想必须有一个更好的方法,但我找不到它。
You may use git to rewrite the urls 您可以使用git重写网址
git config --global url."https://".insteadOf git://
You may include a hostname in the expression to restrict the rewrite to a specific host 您可以在表达式中包含主机名以限制重写到特定主机
git config --global url."https://github.com".insteadOf git://github.com
If you do not whant the rewrite rules to be global then just add it to your local scope instead. 如果您不将重写规则视为全局,则只需将其添加到本地范围即可。
See more under section url.<base>.insteadOf
at http://git-scm.com/docs/git-config 看到根据第更多url.<base>.insteadOf
在http://git-scm.com/docs/git-config
更改.gitmodules
的值是更改子模块协议的常用方法,然后是git submodule sync
以更新远程存储库位置。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.