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


当前回答

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

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

其他回答

最后起作用的是设置http_proxy环境变量。我已经正确地设置了HTTP_PROXY,但git显然更喜欢小写版本。

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

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

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

GIT_CURL_VERBOSE=1

这至少可以让您了解幕后发生了什么。

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

有一种方法可以为特定的URL设置代理,请参阅http.< URL >。*章节在git配置手册。例如,对于https://github.com/,可以这样做

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