首页 文章

如何通过HTTP代理从Git存储库中提取?

提问于
浏览
456

注意:虽然所描述的用例是关于在项目中使用子模块,但同样适用于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) .

26 回答

  • 0

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

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

    这已经有了一些很好的答案 . 但是,我认为我会填写,因为一些代理服务器要求您使用用户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
    

    而已!

  • 539

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

  • 116

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

    GIT_CURL_VERBOSE=1
    

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

  • 14

    当您的网络团队通过重写证书进行ssl检查时,然后使用http url而不是https,并结合设置此var为我工作 .

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

    如果您只想在指定的存储库上使用代理,则不需要在其他存储库上 . 当您使用 git clone 存储库时,最好的方法是 -c, --config <key=value> 选项 . 例如

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

    您也可以 edit .gitconfig file 位于Windows系统上的%userprofile%目录(记事本%userprofile%.gitconfig)或Linux系统上的〜目录(vi~ / .gitconfig)和 add a http section 中,如下所示 .

    .gitconfig文件的内容:

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

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

  • 10

    对我来说,git://虽然https://确实无法通过代理工作 . 这引起了一些麻烦,因为我运行的脚本都使用了git://所以我不能轻易地改变它们 . 但是我找到了这个创业板

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

    我发现我的身份验证的http代理既没有 http.proxy 也没有 GIT_PROXY_COMMAND 工作 . 代理不会以任何方式触发 . 但我找到了解决这个问题的方法 .

    • 安装corkscrew,或您想要的其他替代方案 .

    • 创建一个authfile . authfile 的格式为: user_name:passworduser_namepassword 是您访问代理的用户名和密码 . 要创建这样的文件,只需运行如下命令: echo "username:password" > ~/.ssh/authfile .

    • 编辑 ~/.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做同样的事情 .

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

  • 45

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

    它针对普通甚至Windows NTLM代理对您进行身份验证,并在不进行身份验证的情况下启动localhost-proxy .

    为了让它运行:

    • 安装Cntml

    • 根据文档配置Cntml以传递代理身份验证

    • 将git指向新的localhost代理:

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

    对我来说它的作用是:

    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
    
  • 1

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

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

  • 15

    设置代理到git

    命令

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

    例子

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

    我有同样的问题,修复略有不同: 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
    

    但仍然有致命的错误 .

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

    #define CURLDIR = / foo / bar如果你的curl头文件和库文件在#/ foo / bar / include和/ foo / bar / lib目录中 .

    我记得那时,我没有从源代码中得到 curl ,所以一直在寻找头文件 . 果然,他们没有安装 . 那就是问题所在 . Make没有抱怨丢失的头文件 . 所以我没有意识到 --with-curl 选项什么都没做(实际上是我的 git 版本中的默认选项) .

    我做了以下修复:

    • 添加了make所需的标头:
    yum install curl-devel
    (expat-devel-1.95.8-8.3.el5_5.3.i386  was already installed).
    
    • /usr/local 删除 git (因为我希望新安装在那里生活) .

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

    • 搜索包含 curlexpat 头文件的include目录,然后(因为我已阅读 configure )将这些添加到环境中,如下所示:
    export CURLDIR=/usr/include 
    export EXPATDIR=/usr/include
    
    • Ran configure 使用以下选项,这些选项再次在 configure 文件中进行了描述,也是默认值但是到底是什么:
    ./configure  --with-curl --with-expat
    
    • 现在 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
    ...
    
  • 18

    这对我有用 .

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

    这不是github(或git)的问题 . 在linux上的git-1.6.0.1上它也失败了 . Bug已经报道(由你不少) .

    一定要删除你的馅饼,他们一直在做梦,我想你无法删除它们 . 请改用Gist

  • 22

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

  • 5

    对于Windows

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

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

    [HTTP]

    [HTTPS]

    proxy = https://your_proxy:your_port
    

    [HTTP]

    proxy = http://your_proxy:your_port
    

    How to check your proxy and port number?

    Internet Explorer - >设置 - > Internet选项 - >连接 - >局域网设置

  • 1

    您可以使用:

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

    使用proxychains

    proxychains git pull ...
    

    update: proxychains已停止使用,请改用proxychains-ng .

  • 1

    将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
    

    现在你好好去!

  • 11

    我使用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
    
  • 1

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

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

    我能够推,拉,创造新的回购 . 一切都很好 . 如果您像我一样遇到Git问题,请确保您执行干净卸载并重新安装新版本 .

  • 1

    由于许多人已经回答了这个问题,但这只适用于使用auth支持代理的 Winodws .

    重新安装(首先失败,不要删除) .

    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

  • 0

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

相关问题