简体   繁体   English

如何在github https存储库地址上使用git和ssh?

[英]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>.insteadOfhttp://git-scm.com/docs/git-config

更改.gitmodules的值是更改子模块协议的常用方法,然后是git submodule sync以更新远程存储库位置。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在使用https克隆后,如何SSH git存储库? - How to SSH a git repository after already cloned with https? 如果我使用 https 连接到存储库,如何使用 SSH 密钥? - How is it possible to use SSH key if I connect to a repository using https? 如何在github中使用ssh,似乎它本身全部切换为https? - How to use ssh with github, it seems it's switching to https all by itself? 如何使用SSH将存储库推送到GitHub? - How can I use SSH to push my repository to GitHub? git 克隆无法使用错误“要访问此存储库,您必须使用带有个人访问令牌的 HTTPS 遥控器或带有 SSH 密钥的 SSH” - git clone not working with error " To access this repository, you must use the HTTPS remote with a personal access token or SSH with an SSH key" 限制 Github 访问 ssh 和 https URL 中的单个存储库 - Restrict Github access to a single repository in ssh and https URL 从 Matlab 推送本地 git 存储库失败:您无法推送到 git://github.com/user/repo.git 使用 https://github.com/user/repo.git - Pushing local git repository from Matlab fails: You can't push to git://github.com/user/repo.git use https://github.com/user/repo.git 通过HTTPS或SSH使用Git的最佳方法是什么? - What is the best way to use Git, with HTTPS or with SSH? 如何使用本地git仓库填充github仓库? - How to populate a github repository with local git repository? 尽管仅提供ssh访问,但仍使用https访问git存储库 - Accessing a git repository using https, despite it providing ssh access only
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM