How do I pull from a Git repository through an HTT

2018-12-31 13:56发布

Note: while the use-case described is about using submodules within a project, the same applies to a normal git clone of a repository over HTTP.

I have a project under Git control. I'd like to add a submodule:

git submodule add http://github.com/jscruggs/metric_fu.git vendor/plugins/metric_fu

But I get

...
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'

I have my HTTP_PROXY set up:

c:\project> echo %HTTP_PROXY%
http://proxy.mycompany:80

I even have a global Git setting for the http proxy:

c:\project> git config --get http.proxy
http://proxy.mycompany:80

Has anybody gotten HTTP fetches to consistently work through a proxy? What's really strange is that a few project on GitHub work fine (awesome_nested_set for example), but others consistently fail (rails for example).

26条回答
墨雨无痕
2楼-- · 2018-12-31 14:21

There's some great answers on this already. However, I thought I would chip in as some proxy servers require you to authenticate with a user Id and password. Sometimes this can be on a domain.

So, for example if your proxy server configuration is as follows:

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

Then, add to your .gitconfig file using the following command:

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

Don't worry about https. As long as the specified proxy server supports http, and https, then one entry in the config file will suffice.

You can then verify that the command added the entry to your .gitconfig file successfully by doing cat .gitconfig:

At the end of the file you will see an entry as follows:

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

That's it!

查看更多
明月照影归
3楼-- · 2018-12-31 14:23

For me what it worked was:

sudo apt-get install socat

Create a file inside your $BIN_PATH/gitproxy with:

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

Dont forget to give it execution permissions

chmod a+x gitproxy

Run following commands to setup environment:

export PATH=$BIN_PATH:$PATH
git config --global core.gitproxy gitproxy
查看更多
闭嘴吧你
4楼-- · 2018-12-31 14:28

This is an old question but if you are on Windows, consider setting HTTPS_PROXY as well if you are retrieving via an https URL. Worked for me!

查看更多
倾城一夜雪
5楼-- · 2018-12-31 14:29

If you just want to use proxy on a specified repository, don't need on other repositories. The preferable way is the -c, --config <key=value> option when you git clone a repository. e.g.

$ git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git --config "http.proxy=proxyHost:proxyPort"
查看更多
深知你不懂我心
6楼-- · 2018-12-31 14:29

For me the git:// just doesn't work through the proxy although the https:// does. This caused some bit of headache because I was running scripts that all used git:// so I couldn't just easily change them all. However I found this GEM

git config --global url."https://github.com/".insteadOf git://github.com/
查看更多
旧人旧事旧时光
7楼-- · 2018-12-31 14:30

You can also set the HTTP proxy that Git uses in global configuration property http.proxy:

git config --global http.proxy http://proxy.mycompany:80
查看更多
登录 后发表回答