【问题标题】:How do I pull from a Git repository through an HTTP proxy?如何通过 HTTP 代理从 Git 存储库中提取?
【发布时间】:2010-09-12 18:49:46
【问题描述】:

注意:虽然描述的用例是关于在项目中使用子模块,但同样适用于通过 HTTP 的存储库的普通 git clone

我有一个受 Git 控制的项目。我想添加一个子模块:

git submodule add http://github.com/jscruggs/metric_fu.git vendor/plugins/metric_fu

但我明白了

...
got 1b0313f016d98e556396c91d08127c59722762d0
got 4c42d44a9221209293e5f3eb7e662a1571b09421
got b0d6414e3ca5c2fb4b95b7712c7edbf7d2becac7
error: Unable to find abc07fcf79aebed56497e3894c6c3c06046f913a under http://github.com/jscruggs/metri...
Cannot obtain needed commit abc07fcf79aebed56497e3894c6c3c06046f913a
while processing commit ee576543b3a0820cc966cc10cc41e6ffb3415658.
fatal: Fetch failed.
Clone of 'http://github.com/jscruggs/metric_fu.git' into submodule path 'vendor/plugins/metric_fu'

我已经设置了 HTTP_PROXY:

c:\project> echo %HTTP_PROXY%
http://proxy.mycompany:80

我什至有一个用于 http 代理的全局 Git 设置:

c:\project> git config --get http.proxy
http://proxy.mycompany:80

有没有人通过代理获得 HTTP 提取以始终如一地工作?真正奇怪的是,GitHub 上的一些项目运行良好(例如awesome_nested_set),但其他项目始终失败(例如rails)。

【问题讨论】:

  • 您的代理是否会审查某些单词或其他内容,从而仅影响那些单词恰好作为字节流的一部分出现的那些存储库?
  • @alvaro,我认为您的意思是 Getting git to work with a proxy server 可能与此问题重复。此问题比您所指的问题更早。
  • @James,您对代理服务器的“全局”Git 设置实际上不是全局的,而是本地的。要成为全球性的,您需要将参数 --global 提供给 git config
  • @DerekMahar 如果较新的问题质量更好(或更普遍适用),较旧的问题可能会被关闭,而不是较新的问题。

标签: git proxy git-submodules


【解决方案1】:

看起来您正在 Windows 上使用 Git 的 mingw 编译(或者可能是我没听说过的另一个)。有一些调试方法:我相信 git 的所有 http 代理工作都是由 curl 完成的。在运行 git 之前设置这个环境变量:

GIT_CURL_VERBOSE=1

这至少应该让您了解幕后发生的事情。

【讨论】:

  • 当我添加这个环境变量时,msysgit 不会打印出任何额外的东西。 :(
  • 与代理斗争了一段时间后,这个技巧帮助我发现 curl 的证书数据库丢失/混乱,这就是请求失败的原因。
  • 我找这个已经有一段时间了。谢谢。
【解决方案2】:

这不是您的代理的问题。这是github(或git)的问题。在 Linux 上的 git-1.6.0.1 对我来说也失败了。 Bug 已被举报(由您举报)。

确保删除您的馅饼,它们已经在 Google 上。编辑:一定是在做梦,我猜你不能删除它们。改用Gist

【讨论】:

  • 我也发布到 github 和 msysGit 以及 b/c 我不确定问题出在哪里。很遗憾,我似乎无法删除馅饼。
【解决方案3】:

最终奏效的是设置http_proxy 环境变量。我已经正确设置了HTTP_PROXY,但 git 显然更喜欢小写版本。

【讨论】:

  • 在全局 Git 配置中设置 http.proxy 是否有效?在您的问题中,您在本地存储库配置中设置了 http.proxy
  • 就我而言,我必须设置https_proxy
  • https.proxy 似乎对我有用,因为我在 github 上使用 https
  • @MSmith 如果您必须设置https_proxy,这意味着您使用的是https 而不是http 这是关于哪个问题的。
  • Curl 和 libcurl 无法识别大写 HTTP_PROXY 和 HTTPS_PROXY。有关更多信息,请参阅此链接:curl.haxx.se/mail/archive-2001-12/0034.html
【解决方案4】:

你也可以在全局配置属性http.proxy中设置Git使用的HTTP代理:

git config --global http.proxy http://proxy.mycompany:80

使用代理进行身份验证:

git config --global http.proxy http://mydomain\\myusername:mypassword@myproxyserver:8080/

(认证格式为@EugeneKulabuhov@JaimeReynoso。)

【讨论】:

  • 这对我有用:在用户环境中设置 HTTP_PROXY(在 Windows 上),然后使用 $HTTP_PROXY(大写)进行上述注释。对此解决方案 +1。
  • CleverCoder,在 Windows 上,您需要指定 %HTTP_PROXY%,而不是 $HTTP_PROXY(当然,除非您正在运行 Cygwin)。我将编辑我的答案以在 Windows 而不是 Unix 环境中工作。
  • 代理的用户名和密码放在哪里?
  • 使用git config --global http.proxy http://mydomain\\myusername:mypassword@myproxyserver:8080 语法提供用户名/密码
  • 对于任何可能遇到代理问题的人,http://:@:/ 为我工作
【解决方案5】:

这是一个老问题,但如果您使用的是 Windows,请考虑设置 HTTPS_PROXY 以及通过 https URL 检索。为我工作!

【讨论】:

  • 在我的情况下(Windows XP 上的 msysgit)单独设置 https_proxy 环境变量(没有设置 git 全局或 repo 代理选项)就足够了。
【解决方案6】:

只是发布这个因为它是谷歌上的第一个结果,我发现这篇博文通过更新 curl 证书为我解决了这个问题。

http://www.simplicidade.org/notes/archives/2011/06/github_ssl_ca_errors.html

【讨论】:

【解决方案7】:

我遇到了同样的问题,但修复方法略有不同:REBUILDING GIT WITH HTTP SUPPORT

git: 协议无法通过我的公司防火墙。

例如,这个超时:

git clone git://github.com/miksago/node-websocket-server.git

curl github.com 工作得很好,所以我知道我的http_proxy 环境变量是正确的。

我尝试使用http,如下所示,但立即出现错误。

git clone http://github.com/miksago/node-websocket-server.git

->>>  fatal: Unable to find remote helper for 'http' <<<-

我尝试像这样重新编译 git:

./configure  --with-curl --with-expat

但仍然出现致命错误。

最后,经过几个令人沮丧的小时后,我阅读了配置文件, 看到了这个:

# 定义 CURLDIR=/foo/bar 如果你的 curl 头文件和库文件在里面

# /foo/bar/include 和 /foo/bar/lib 目录。

我记得当时我没有从源头遵守curl,所以去了 寻找头文件。果然,它们没有安装。这就是问题所在。 Make 没有抱怨丢失的头文件。所以 我没有意识到--with-curl 选项什么也没做(事实上,这是我的git 版本中的默认选项)。

我做了以下修复:

  1. 添加了make所需的头文件:

    yum install curl-devel
    (expat-devel-1.95.8-8.3.el5_5.3.i386  was already installed).
    
  2. /usr/local 中删除了git(因为我希望新的安装存在于那里)。

    我只是从/usr/local/share/usr/local/libexec 中删除了git*

  3. 搜索包含curlexpat 头文件的包含目录,然后(因为我已经阅读了configure)将这些添加到环境中,如下所示:

    export CURLDIR=/usr/include 
    export EXPATDIR=/usr/include
    
  4. 使用以下选项运行 configure,这些选项再次在 configure 文件本身中进行了描述,也是默认设置,但到底是什么:

    ./configure  --with-curl --with-expat
    
  5. 现在http 可以通过我的公司防火墙与git 一起使用:

    git clone http://github.com/miksago/node-websocket-server.git
    Cloning into 'node-websocket-server'...
    * Couldn't find host github.com in the .netrc file, using defaults
    * About to connect() to proxy proxy.entp.attws.com port 8080
    *   Trying 135.214.40.30... * connected
    ...
    

【讨论】:

  • 我很高兴你把这个放在前面,我没有意识到我的 squid 代理上没有处理 git 协议
【解决方案8】:

您也可以编辑 .gitconfig 文件,该文件位于 Windows 系统上的 %userprofile% 目录(notepad %userprofile%.gitconfig)或 Linux 系统上的 ~ 目录中(vi ~/.gitconfig) 和 添加 http 部分,如下所示。

.gitconfig 文件内容:

[http]
        proxy = http://proxy.mycompany:80

【讨论】:

    【解决方案9】:

    已经有一些很好的答案。但是,我想我会加入,因为某些代理服务器要求您使用用户 ID 和密码进行身份验证。有时这可以在域上。

    所以,比如你的代理服务器配置如下:

    Server: myproxyserver
    Port: 8080
    Username: mydomain\myusername
    Password: mypassword
    

    然后,使用以下命令添加到您的 .gitconfig 文件:

    git config --global http.proxy http://mydomain\\myusername:mypassword@myproxyserver:8080
    

    不用担心https。只要指定的代理服务器支持http、https,那么配置文件中的一项就足够了。

    然后您可以通过执行cat .gitconfig 验证该命令是否已成功将条目添加到您的.gitconfig 文件中:

    在文件的末尾,您将看到如下条目:

    [http]
        proxy = http://mydomain\\myusername:mypassword@myproxyserver:8080
    

    就是这样!

    【讨论】:

    • 有趣。我能够以 100% 的速度进入“解决增量”部分,但看起来克隆过程只是挂起。有人经历过吗?
    • +1。很快,你就可以to setup proxy per url!
    • @apoplexy 你能评论你建议的编辑吗,以便我考虑
    • 如果您的用户名或密码中有@符号,那么您可以对其进行URL编码%40,它会起作用。
    • 你可以使用 git config --list 列出配置设置,而不是 cat .gitconfig
    【解决方案10】:

    当您的网络团队通过重写证书进行 ssl-inspection 时,然后使用 http url 而不是 https ,并结合设置此 var 对我有用。

    git config --global http.proxy http://proxy:8081
    

    【讨论】:

    • 您也可以将其添加到环境中以接受网络家伙提供的重写证书以检查您的流量:export GIT_SSL_NO_VERIFY=true
    • 完美地为我工作。谢谢。我只需要添加 git config --global http.proxy proxy:8081 git config --global https.proxy proxy:8081
    • 简单快捷的解决方案,为这个答案+1。
    • 感谢@sethbc,@datasmid!我需要 GIT_CURL_VERBOSE=1 来调试和 GIT_SSL_NO_VERIFY=true 来跳过验证。
    • 不和我一起工作。甚至没有 GIT_SSL_NO_VERIFY var
    【解决方案11】:

    $http_proxy 用于http://github.com.... $https_proxy 用于https://github.com...

    【讨论】:

      【解决方案12】:

      我发现 http.proxyGIT_PROXY_COMMAND 都不适用于我经过身份验证的 http 代理。代理不会以任何一种方式触发。但我找到了解决这个问题的方法。

      1. 安装corkscrew,或您想要的其他替代方案。
      2. 创建身份验证文件。 authfile 的格式为:user_name:passworduser_namepassword 是您访问代理的用户名和密码。要创建这样的文件,只需运行如下命令:echo "username:password" &gt; ~/.ssh/authfile

      3. 编辑~/.ssh/config,并确保其权限为644chmod 644 ~/.ssh/config

      以github.com为例,在~/.ssh/config中加入如下几行:

      Host    github.com
              HostName        github.com
              ProxyCommand    /usr/local/bin/corkscrew <your.proxy> <proxy port> %h %p <path/to/authfile>
              User            git
      

      现在,无论您何时使用git@github.com,它都会自动使用代理。您也可以轻松地对Bitbucket 执行相同的操作。

      这不像其他方法那么优雅,但它就像一个魅力。

      【讨论】:

      • 您能否详细说明第 2 步“创建身份验证文件”?看来您的方法是唯一适用于 git:// urls 的方法。
      • @NikBagdon 我在第 2 步中添加了更多详细信息。如果有不清楚的地方请告诉我:)
      【解决方案13】:

      当我的代理不需要身份验证时,上述答案对我有用。如果您使用需要您进行身份验证的代理,那么您可以尝试 CCProxy。我这里有关于如何设置的小教程,

      http://blog.praveenkumar.co.in/2012/09/proxy-free-windows-xp78-and-mobiles.html

      我能够推送、拉取、创建新的存储库。一切正常。如果您像我一样遇到 Git 问题,请确保彻底卸载并重新安装新版本。

      【讨论】:

        【解决方案14】:

        在 Windows 上,如果您不想将密码以纯文本形式放在 .gitconfig 中,可以使用

        它会根据普通甚至 Windows NTLM 代理对您进行身份验证,并在没有身份验证的情况下启动 localhost-proxy。

        为了让它运行:

        • 安装 Cntml
        • 根据文档配置 Ctml 以通过您的代理身份验证
        • 将 git 指向您的新 localhost 代理:

          [http]
              proxy = http://localhost:3128       # change port as necessary
          

        【讨论】:

        • 对于它的价值,这应该是公认的答案,他在 Windows 上。没有透明代理(否则不会有问题。
        【解决方案15】:

        我使用 https 绕过代理...有些代理甚至不检查 https。

        Microsoft Windows [Version 6.1.7601]
        Copyright (c) 2009 Microsoft Corporation.  All rights reserved.
        
        c:\git\meantest>git clone http://github.com/linnovate/mean.git
        Cloning into 'mean'...
        fatal: unable to access 'http://github.com/linnovate/mean.git/': Failed connect
        to github.com:80; No error
        
        c:\git\meantest>git clone https://github.com/linnovate/mean.git
        Cloning into 'mean'...
        remote: Reusing existing pack: 2587, done.
        remote: Counting objects: 27, done.
        remote: Compressing objects: 100% (24/24), done.
        rRemote: Total 2614 (delta 3), reused 4 (delta 0)eceiving objects:  98% (2562/26
        
        Receiving objects: 100% (2614/2614), 1.76 MiB | 305.00 KiB/s, done.
        Resolving deltas: 100% (1166/1166), done.
        Checking connectivity... done
        

        【讨论】:

          【解决方案16】:

          如果您只想在指定的存储库上使用代理,则不需要在其他存储库上。当您 git clone 存储库时,更可取的方法是 -c, --config &lt;key=value&gt; 选项。例如

          $ git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git --config "http.proxy=proxyHost:proxyPort"
          

          【讨论】:

          • 这很奇怪,我尝试设置$http_proxy,但git不尊重它。看起来它只关心自己的配置......
          • 有效。您还可以多次指定--config,例如当你还想设置https.proxy时。
          • 谢谢!正是我想要的
          • 使用代理配置进行克隆,但不更改用户的代理配置。正是我需要的!谢谢。
          • --config "core.gitProxy..." howto,我想代理ssh协议,没有全局代理设置,thx.@alijandro
          【解决方案17】:

          对我来说,它的作用是:

          sudo apt-get install socat
          

          在你的 $BIN_PATH/gitproxy 中创建一个文件:

          #!/bin/sh 
          _proxy=192.168.192.1 
          _proxyport=3128 
          exec socat STDIO PROXY:$_proxy:$1:$2,proxyport=$_proxyport
          

          别忘了给它执行权限

          chmod a+x gitproxy
          

          运行以下命令设置环境:

          export PATH=$BIN_PATH:$PATH
          git config --global core.gitproxy gitproxy
          

          【讨论】:

          • 解释链接和(迷你)脚本更新的要点链接:emilsit.net/blog/archives/…
          • 此答案是唯一适用于git:// 协议 URL 的答案,适用于那些(罕见的)不支持 https 的 git 服务器。也适用于 windows,带有适当的批处理文件和适用于 windows 的 socat。
          【解决方案18】:

          对我来说 git:// 只是不能通过代理工作,尽管 https:// 可以。这引起了一些头痛,因为我正在运行所有使用 git:// 的脚本,所以我不能轻易地全部更改它们。但是我发现了这个 GEM

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

          【讨论】:

          • 谢谢,帮了大忙
          • 我知道我也有问题要从 git:// 中提取。您是否考虑过 SSH 密钥问题?我的问题是由于 SSH 密钥配置错误造成的。
          【解决方案19】:

          对于 Windows

          转到 --> C:/Users/user_name/gitconfig

          使用以下详细信息更新 gitconfig 文件

          [http]

          [https]

          proxy = https://your_proxy:your_port
          

          [http]

          proxy = http://your_proxy:your_port
          

          如何查看您的代理和端口号?

          Internet Explorer -> 设置 -> Internet 选项 -> 连接 -> LAN 设置

          【讨论】:

            【解决方案20】:

            正如许多人回答的那样,但这仅适用于具有身份验证的代理背后的 Winodws USER。

            重新安装(第一次失败,不要删除)。

            Goto ->
            **Windows**
            1. msysgit\installer-tmp\etc\gitconfig
                Under [http]
                    proxy = http://user:pass@url:port
            
            **Linux**
            1. msysgit\installer-tmp\setup-msysgit.sh
                  export HTTP_PROXY="http://USER:PASS@proxy.abc.com:8080"
            

            如果您在用户/密码中有任何特殊字符,请使用 url_encode

            【讨论】:

              【解决方案21】:

              正如@user2188765 已经指出的那样,尝试用http[s]:// 替换存储库的git:// 协议。另见this answer

              【讨论】:

                【解决方案22】:

                这对我有用。

                git config --global http.proxy proxy_user:proxy_passwd@proxy_ip:proxy_port
                

                【讨论】:

                  【解决方案23】:

                  设置代理到 git

                  命令

                  git config --global http.proxy http://user:password@domain:port
                  

                  示例

                  git config --global http.proxy http://clairton:123456@proxy.clairtonluz.com.br:8080
                  

                  【讨论】:

                    【解决方案24】:

                    你可以使用:

                    git config --add http.proxy http://user:password@proxy_host:proxy_port
                    

                    【讨论】:

                      【解决方案25】:

                      使用proxychains

                      proxychains git pull ...
                      

                      更新:代理链已停用,请改用proxychains-ng

                      【讨论】:

                      • 不幸的是只有 Unix
                      • @Samoth Jun,对于 Windows,您可能想试试 SocksCap64
                      【解决方案26】:

                      将 Git credential.helper 设置为 wincred。

                      git config --global credential.helper wincred
                      

                      确保只有 1 个 credential.helper

                      git config -l
                      

                      如果超过 1 且未设置为 wincred,则将其删除。

                      git config --system --unset credential.helper
                      

                      现在设置没有密码的代理。

                      git config --global http.proxy http://<YOUR WIN LOGIN NAME>@proxy:80
                      

                      检查您添加的所有设置是否正常......

                      git config --global -l
                      

                      现在你可以开始了!

                      【讨论】:

                        【解决方案27】:

                        以下方法适用于我:

                        echo 'export http_proxy=http://username:password@roxy_host:port/' >> ~/.bash_profile
                        echo 'export https_proxy=http://username:password@roxy_host:port' >> ~/.bash_profile
                        
                        • Zsh 注意:修改您的 ~/.zshenv 文件而不是 ~/.bash_profile。
                        • Ubuntu 和 Fedora 注意:修改您的 ~/.bashrc 文件而不是 ~/.bash_profile。

                        【讨论】:

                          【解决方案28】:

                          值得一提: 网上大部分例子显示examples like

                          git config --global http.proxy proxy_user:proxy_passwd@proxy_ip:proxy_port
                          

                          看来,如果您的代理需要身份验证,您必须将公司密码保留在 git-config 中。这不是很酷。

                          但是,如果你只是配置没有密码的用户:

                          git config --global http.proxy proxy_user@proxy_ip:proxy_port
                          

                          Git 似乎(至少在我没有凭据助手的 Windows 机器上)能够识别它并在 repo-access 时提示输入代理密码。

                          【讨论】:

                          • 你是我的人,因为我的 sso 公司用户名和密码有很多特殊的符号,编码和通过是非常不可能的。有了这个“escamotage”,我可以在克隆人脸上提供密码,或者在设置代理地址后提供任何其他后续步骤。
                          【解决方案29】:

                          有一种方法可以为特定 URL 设置代理,请参阅 git config 手册中的 http.<url>.* section。例如,https://github.com/ 可以这样做

                          git config --global 'http.https://github.com/.proxy' http://proxy.mycompany:80
                          

                          【讨论】:

                            猜你喜欢
                            • 1970-01-01
                            • 1970-01-01
                            • 1970-01-01
                            • 1970-01-01
                            • 1970-01-01
                            相关资源
                            最近更新 更多