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


当前回答

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

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时提示输入代理密码。

其他回答

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

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

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时提示输入代理密码。

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

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

你可以使用:

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

安装代理到git

命令

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

例子

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