如何将`git:` url 转换为`http:` url

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1722807/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 07:20:08  来源:igfitidea点击:

How to convert `git:` urls to `http:` urls

gitproxy

提问by noamtm

I'm working behind an http proxy. I'm trying to clone Android's source tree using their "repo" tool.

我在 http 代理后面工作。我正在尝试使用他们的“repo”工具克隆 Android 的源代码树。

This tool insists on using git://URLs, even though http://URLs also work. As a result, I can't download the source.

该工具坚持使用git://URL,即使http://URL 也有效。结果,我无法下载源代码。

Is it possible to force gitto always use http?

是否可以强制git始终使用http

Edit:my http_proxy is configured correctly. For example, this works:

编辑:我的 http_proxy 配置正确。例如,这有效:

git clone http://android.git.kernel.org/platform/manifest.git

But this doesn't (errno=Connection timed out):

但这不会(errno=Connection timed out):

git clone git://android.git.kernel.org/platform/manifest.git

So this answerdoes not really help me.

所以这个答案并没有真正帮助我。

回答by Tobu

Here's an example of rewriting the default protocol for GitHub:

以下是为 GitHub 重写默认协议的示例:

git config --global url.https://github.com/.insteadOf git://github.com/

回答by Jakub Nar?bski

I don't know how this repotool uses Git (and if you can configure 'repo' to use http protocol), but you can try to trick it using url.<base>.insteadOfconfiguration variable (see git-configand git-fetchmanpages).

我不知道这个repo工具如何使用 Git(如果你可以配置 'repo' 以使用 http 协议),但你可以尝试使用url.<base>.insteadOf配置变量来欺骗它(参见git-configgit-fetch手册页)。

Have you tried to use core.gitProxyto pass through firewall, if it is the problme with using git protocol?

您是否尝试过使用core.gitProxy通过防火墙,如果是使用git协议的问题?

回答by crcastle

I had this same problem with recursively getting submodules in a git repository. I'm behind a crazy firewall that doesn't allow outgoing connections on the git port. Some of the submodules of the submodules were coded as git://github.com/blah/blah.git. This killed my recursive population of submodules. The workaround is the following:

我在 git 存储库中递归获取子模块时遇到了同样的问题。我在一个疯狂的防火墙后面,它不允许在 git 端口上进行传出连接。子模块的一些子模块被编码为git://github.com/blah/blah.git. 这杀死了我递归的子模块群。解决方法如下:

git config --global url."https://<GITUSERNAME>@".insteadOf git://

This replaces git://with https://<GITUSERNAME>@in all submodule repository URLs. You need to replace <GITUSERNAME>with your own git username. Also note that the --globalis required; just adding this configuration to the base repository directory doesn't work.

这将替换git://https://<GITUSERNAME>@在所有子模块库URL。您需要替换<GITUSERNAME>为您自己的 git 用户名。另请注意,--global是必需的;仅将此配置添加到基本存储库目录是行不通的。

回答by piperchester

You can verify in ~/.gitconfigif you're overwriting SSH with https://, or vice versa.

您可以验证~/.gitconfig是否使用 https:// 覆盖 SSH,反之亦然。