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:35

What finally worked was setting the http_proxy environment variable. I had set HTTP_PROXY correctly, but git apparently likes the lower-case version better.

查看更多
皆成旧梦
3楼-- · 2018-12-31 14:37

It looks like you're using a mingw compile of Git on windows (or possibly another one I haven't heard about). There are ways to debug this: I believe all of the http proxy work for git is done by curl. Set this environment variable before running git:

GIT_CURL_VERBOSE=1

This should at least give you an idea of what is going on behind the scenes.

查看更多
裙下三千臣
4楼-- · 2018-12-31 14:37

I find neither http.proxy nor GIT_PROXY_COMMAND work for my authenticated http proxy. The proxy is not triggered in either way. But I find a way to work around this.

  1. Install corkscrew, or other alternatives you want.
  2. Create a authfile. The format for authfile is: user_name:password, and user_name, password is your username and password to access your proxy. To create such a file, simply run command like this: echo "username:password" > ~/.ssh/authfile.

  3. Edit ~/.ssh/config, and make sure its permission is 644: chmod 644 ~/.ssh/config

Take github.com as an example, add the following lines to ~/.ssh/config:

Host    github.com
        HostName        github.com
        ProxyCommand    /usr/local/bin/corkscrew <your.proxy> <proxy port> %h %p <path/to/authfile>
        User            git

Now whenever you do anything with git@github.com, it will use the proxy automatically. You can easily do the same thing to Bitbucket as well.

This is not so elegant as other approaches, but it works like a charm.

查看更多
长期被迫恋爱
5楼-- · 2018-12-31 14:37

This isn't a problem with your proxy. It's a problem with github (or git). It fails for me on git-1.6.0.1 on linux as well. Bug is already reported (by you no less).

Make sure to delete your pasties, they're already on google. Edit: Must've been dreaming, i guess you can't delete them. Use Gist instead?

查看更多
初与友歌
6楼-- · 2018-12-31 14:37

$http_proxy is for http://github.com.... $https_proxy is for https://github.com...

查看更多
一个人的天荒地老
7楼-- · 2018-12-31 14:38

This worked to me.

git config --global http.proxy proxy_user:proxy_passwd@proxy_ip:proxy_port
查看更多
登录 后发表回答