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

时间:2008-09-24 15:58:33

标签: git proxy git-submodules

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

29 个答案:

答案 0 :(得分:554)

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

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

使用代理进行身份验证:

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

(对于身份验证格式,信用转到@EugeneKulabuhov@JaimeReynoso。)

答案 1 :(得分:145)

这已经有了一些很好的答案。但是,我认为我会填写,因为一些代理服务器要求您使用用户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,配置文件中的一个条目就足够了。

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

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

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

就是这样!

答案 2 :(得分:120)

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

答案 3 :(得分:48)

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

之前设置此环境变量
GIT_CURL_VERBOSE=1

这至少可以让你了解幕后发生的事情。

答案 4 :(得分:27)

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

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

答案 5 :(得分:25)

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

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

答案 6 :(得分:19)

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

.gitconfig文件的内容:

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

答案 7 :(得分:16)

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

答案 8 :(得分:15)

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

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

答案 9 :(得分:11)

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

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

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

  4. 以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执行相同的操作。

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

答案 10 :(得分:10)

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

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

为了让它运行:

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

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

答案 11 :(得分:6)

对我而言,它的作用是:

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

答案 12 :(得分:5)

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

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

答案 13 :(得分:5)

设置代理到git

命令

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

例如

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

答案 14 :(得分:4)

这对我有用。

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

答案 15 :(得分:3)

将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

现在好了!

答案 16 :(得分:3)

我遇到了同样的问题,修复方式稍有不同:使用HTTP支持重新构建GIT

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版本中的默认选项)。

我做了以下修复:

  1. 添加了make:

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

    我只是从git*/usr/local/share

  3. 删除了/usr/local/libexec
  4. 搜索包含curlexpat标头文件的include目录,然后(因为我已阅读configure)将这些添加到环境中,如下所示:< / p>

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

    ./configure  --with-curl --with-expat
    
  6. 现在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
    ...
    

答案 17 :(得分:2)

你可以使用:

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

答案 18 :(得分:1)

使用proxychains

proxychains git pull ...

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

答案 19 :(得分:1)

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

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

答案 20 :(得分:1)

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

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

答案 21 :(得分:1)

适用于Windows

转到 - &gt; C:/用户/ USER_NAME / gitconfig

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

[HTTP]

[HTTPS]

proxy = https://your_proxy:your_port

[HTTP]

proxy = http://your_proxy:your_port

如何检查代理和端口号?

Internet Explorer - &gt;设置 - &gt;互联网选项 - &gt;连接 - &gt;局域网设置

答案 22 :(得分:1)

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

答案 23 :(得分:0)

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

答案 24 :(得分:0)

许多人都回答了这个问题,但这只适用于使用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

中有任何特殊字符

答案 25 :(得分:0)

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

答案 26 :(得分:0)

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

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

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

答案 27 :(得分:0)

以下方法对我有用:

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 :(得分:0)

值得一提的是: 网上的大多数示例都显示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机器上)识别出该错误,并在回购访问时提示输入代理密码。

相关问题