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

我有一个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)。


当前回答

我绕过代理使用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

其他回答

值得一提的是: 网上的大多数例子都是这样的

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机器上)可以识别这一点,并在repi -access时提示输入代理密码。

下面的方法适合我:

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注意:修改你的~/。bashc文件代替~/.bash_profile。

我也遇到了同样的问题,但修复方法略有不同:使用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

但还是犯了致命的错误。

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

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

然后我想起来了,我没有从源头上遵从curl,所以就去了 查找头文件。果然没有安装。这就是问题所在。Make没有抱怨丢失头文件。所以 我没有意识到——with-curl选项什么都没有做(事实上,在我的git版本中它是默认的)。

我做了以下来修复它:

Added the headers needed for make: yum install curl-devel (expat-devel-1.95.8-8.3.el5_5.3.i386 was already installed). Removed git from /usr/local (as I want the new install to live there). I simply removed git* from /usr/local/share and /usr/local/libexec Searched for the include dirs containing the curl and expat header files, and then (because I had read through configure) added these to the environment like so: export CURLDIR=/usr/include export EXPATDIR=/usr/include Ran configure with the following options, which, again, were described in the configure file itself, and were also the defaults but what the heck: ./configure --with-curl --with-expat And now http works with git through my corporate firewall: 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 ...

你也可以在全局配置属性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。)

对于Windows

转到-> C:/用户名/gitconfig

用以下细节更新gitconfig文件

(http)

(https)

proxy = https://your_proxy:your_port

(http)

proxy = http://your_proxy:your_port

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

ie浏览器—>设置—> Internet选项—>连接—>局域网设置