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


当前回答

对我来说,它起作用的是:

sudo apt-get install socat

在$BIN_PATH/gitproxy中创建一个文件:

#!/bin/sh 
_proxy=192.168.192.1 
_proxyport=3128 
exec socat STDIO PROXY:$_proxy:$1:$2,proxyport=$_proxyport

别忘了给它执行权限

chmod a+x gitproxy

运行以下命令设置环境:

export PATH=$BIN_PATH:$PATH
git config --global core.gitproxy gitproxy

其他回答

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

.gitconfig文件内容:

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

如果您只想在指定的存储库上使用代理,则不需要在其他存储库上使用代理。在git克隆存储库时,更可取的方法是-c,——config <key=value>选项。如。

$ git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git --config "http.proxy=proxyHost:proxyPort"

关于这个问题已经有一些很好的答案了。但是,我想我可以凑钱,因为一些代理服务器要求您使用用户Id和密码进行身份验证。有时这可能是在一个域中。

例如,如果你的代理服务器配置如下:

Server: myproxyserver
Port: 8080
Username: mydomain\myusername
Password: mypassword

然后,使用以下命令添加到您的.gitconfig文件:

git config --global http.proxy http://mydomain\\myusername:mypassword@myproxyserver:8080

不要担心https。只要指定的代理服务器支持http和https,那么配置文件中的一个条目就足够了。

然后,您可以通过执行cat .gitconfig命令来验证该命令是否成功地将条目添加到您的.gitconfig文件中:

在文件的末尾,你会看到如下的条目:

[http]
    proxy = http://mydomain\\myusername:mypassword@myproxyserver:8080

就是这样!

对于Windows

转到-> C:/用户名/gitconfig

用以下细节更新gitconfig文件

(http)

(https)

proxy = https://your_proxy:your_port

(http)

proxy = http://your_proxy:your_port

如何检查您的代理和端口号?

ie浏览器—>设置—> Internet选项—>连接—>局域网设置

对我来说,它起作用的是:

sudo apt-get install socat

在$BIN_PATH/gitproxy中创建一个文件:

#!/bin/sh 
_proxy=192.168.192.1 
_proxyport=3128 
exec socat STDIO PROXY:$_proxy:$1:$2,proxyport=$_proxyport

别忘了给它执行权限

chmod a+x gitproxy

运行以下命令设置环境:

export PATH=$BIN_PATH:$PATH
git config --global core.gitproxy gitproxy