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


当前回答

我发现都不是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做同样的事情。

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

其他回答

当我的代理不需要身份验证时,上面的答案对我有用。如果您正在使用需要您进行身份验证的代理,那么您可以尝试CCProxy。我有一个关于如何设置的小教程,

http://blog.praveenkumar.co.in/2012/09/proxy-free-windows-xp78-and-mobiles.html

我可以推,拉,创造新的回购。一切都很顺利。如果你像我一样遇到Git的问题,请确保你干净地卸载并重新安装新版本。

安装代理到git

命令

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

例子

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

你可以使用:

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

你也可以在Windows系统的%userprofile%目录(notepad %userprofile%.gitconfig)或Linux系统的~目录(vi ~/.gitconfig)中编辑。gitconfig文件,并添加如下所示的http部分。

.gitconfig文件内容:

[http]
        proxy = http://proxy.mycompany:80

这是许多人的回答,但这只是为windows用户谁是背后的代理与认证。

重新安装(第一次失败,不要删除)。

Goto ->
**Windows**
1. msysgit\installer-tmp\etc\gitconfig
    Under [http]
        proxy = http://user:pass@url:port

**Linux**
1. msysgit\installer-tmp\setup-msysgit.sh
      export HTTP_PROXY="http://USER:PASS@proxy.abc.com:8080"

如果在user/pass中有任何特殊字符,请使用url_encode