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


当前回答

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

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

其他回答

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

这是一个老问题,但如果你是在Windows上,如果你是通过https URL检索,也可以考虑设置HTTPS_PROXY。为我工作!

对我来说,git://只是不通过代理,尽管https://可以。这引起了一些头痛,因为我运行的脚本都使用git://,所以我不能简单地更改它们。然而,我发现了这个GEM

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

设置Git凭证。助我一臂之力。

git config --global credential.helper wincred

确保只有1个credential.helper

git config -l

如果有多于1且未设置为将其移除。

git config --system --unset credential.helper

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

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

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

git config --global -l

现在你可以开始了!

下面的方法适合我:

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。