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

其他回答

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

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

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上,如果您不想将密码以纯文本形式放在.gitconfig中,您可以使用

中新 (http://cntlm.sourceforge.net/)

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

为了让它运行:

安装Cntml 根据文档配置Cntml以通过代理身份验证 指向git到新的本地主机代理: (http) Proxy = http://localhost:3128 #根据需要更改端口

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

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

我发现都不是http。代理或GIT_PROXY_COMMAND为我的认证http代理工作。这两种方式都不会触发代理。但我找到了解决办法。

安装开瓶器,或其他你想要的替代品。 创建一个authfile。authfile的格式为:user_name:password, user_name, password是您访问代理的用户名和密码。要创建这样的文件,只需执行如下命令:echo "username:password" > ~/.ssh/authfile。 编辑~ /。chmod 644 ~/.ssh/config,并确保其权限为644

以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做同样的事情。

这种方法不像其他方法那样优雅,但它非常有效。