【问题标题】:How to convert `git:` urls to `http:` urls如何将 `git:` url 转换为 `http:` url
【发布时间】:2010-12-15 22:05:24
【问题描述】:

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

此工具坚持使用git:// URL,尽管http:// URL 也可以使用。结果,我无法下载源代码。

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

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

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

但这不会(errno=连接超时):

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

所以this answer 并没有真正帮助我。

【问题讨论】:

标签: git proxy


【解决方案1】:

这里是一个重写 GitHub 的默认协议的例子:

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

url.<base>.insteadOf 的 Git 文档:

git config [--global] url.<base>.insteadOf <other_url>

以该值开头的任何 URL 都将被重写为以 <base> 开头。当多个 insteadOf 字符串与给定 URL 匹配时,将使用最长的匹配项。

【讨论】:

  • 帮助防火墙阻止 git 协议! :)
  • 我可以在这里问一个问题吗?我正在使用它,但写的是“heeps”而不是“https”。我该如何纠正? 'git config --global.url.github.com/.insteadOfheeps://github.com/' 工作吗?
  • 提示:git remote -v 立即显示insteadOfpushInsteadOf 配置的效果
  • 这在公共 WiFi 中对我有用,并且 22 端口被阻塞。如何将配置恢复为默认值?
  • 这个答案几乎对我有用,除了我的存储库使用git@github.com:... 格式的网址。这对我有用:git config --global url."https://github.com/".insteadOf 'git@github.com:'
【解决方案2】:

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

你有没有尝试过使用core.gitProxy穿越防火墙,如果是使用git协议的问题?

【讨论】:

  • 谢谢,这个“insteadOf”变量正是我所需要的。
【解决方案3】:

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

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

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

【讨论】:

【解决方案4】:

如果您使用 https:// 覆盖 SSH,您可以在 ~/.gitconfig 中验证,反之亦然。

【讨论】:

    【解决方案5】:

    找到你的git账号的git配置文件(.gitconfig),修改如下:

        [user]
        email = your e-mail account
    
    
        name = your git account
        [url "git@github.com:"]
    
    
        insteadOf = https://github.com/
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-12-03
      • 2010-09-12
      • 1970-01-01
      • 2021-07-27
      相关资源
      最近更新 更多