Getting git to work with a proxy server

2018-12-31 09:45发布

How do I get git to use a proxy server?

I need to check out code from a git server, it shows "Request timed out" every time. How do I get around this?

Alternatively, how can I set a proxy server?

18条回答
ら面具成の殇う
2楼-- · 2018-12-31 09:57

If you are using ubuntu, then do the following ...

Step 1 : Install corkscrew

$ sudo apt-get install corkscrew

Step 2 : Write a script named git-proxy.sh and add the following

#!/bin/sh

exec corkscrew <name of proxy server> <port> $*

# <name_of_proxy_server> and <port> are the ip address and port of the server
# e.g. exec corkscrew 192.168.0.1 808 $*

Step 3 : Make the script executable

$ chmod +x git-proxy.sh

Step 4 : Set up the proxy command for GIT by setting the environment variable

$ export GIT_PROXY_COMMAND="/<path>/git-proxy.sh"

Now use the git commands,such as

git clone git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
查看更多
与君花间醉酒
3楼-- · 2018-12-31 09:57

In addition of thse answers, I found helpful to consider these 2 points:

One may need to enforce an authentication scheme:

[http]
    # https://github.com/git/git/blob/master/Documentation/config.txt
    proxyAuthMethod = anyauth|basic|digest|negotiate|ntlm

Also, typically with NTLM authentication schema, one may need to provide explicitely the AD domain.

In git bash:

echo %userdomain%

And update the http.proxy accordingly:

git config --global http.proxy http://DOMAIN\\proxyuser:proxypwd@proxy.server.com:8080

Anyway, investigation may be helped by adding CURL logs:

export GIT_CURL_VERBOSE=1
查看更多
明月照影归
4楼-- · 2018-12-31 10:00

Faced same issue because of multiple .gitconfig files in windows, followed below steps to fix the same:

Step 1: Open Git BASH

Step 2: Look for .gitconfig, executing following command:

git config --list --global --show-origin

Step 3: Copy the below content in .gitconfig:

[http]
    proxy = http://YOUR_PROXY_USERNAME:YOUR_PROXY_PASSWORD@YOUR.PROXY.SERVER:YOUR.PROXY.SERVER.PORT
    sslverify = false
[https]
    proxy = http://YOUR_PROXY_USERNAME:YOUR_PROXY_PASSWORD@YOUR.PROXY.SERVER:YOUR.PROXY.SERVER.PORT
    sslverify = false
[url "http://github.com/"]
    insteadOf = git://github.com/

[user]
    name = Arpit Aggarwal
    email = aggarwalarpit.89@gmail.com
查看更多
时光乱了年华
5楼-- · 2018-12-31 10:01

This worked for me, in windows XP behind a corporate firewall.

I didnt have to install any local proxy or any other software besides git v1.771 from http://code.google.com/p/msysgit/downloads/list?can=3

$ git config --global http.proxy http://proxyuser:proxypwd@proxy.server.com:8080
$ git config --system http.sslcainfo /bin/curl-ca-bundle.crt
$ git remote add origin https://mygithubuser:mygithubpwd@github.com/repoUser/repoName.git
$ git push origin master

proxyuser= the proxy user I was assigned by our IT dept, in my case it is the same windows user I use to log in to my PC, the Active Directory user

proxypwd= the password of my proxy user

proxy.server.com:8080 = the proxy name and port, I got it from Control Panel, Internet Options, Connections, Lan Settings button, Advanced button inside the Proxy Server section, use the servername and port on the first (http) row.

mygithubuser = the user I use to log in to github.com

mygithubpwd = the password for my github.com user

repoUser = the user owner of the repo

repoName = the name of the repo

查看更多
谁念西风独自凉
6楼-- · 2018-12-31 10:02

For the git protocol (git://...), install socat and write a script such as:

#!/bin/sh

exec socat - socks4:your.company.com:$1:$2

make it executable, put it in your path, and in your ~/.gitconfig set core.gitproxy to the name of that script.

查看更多
公子世无双
7楼-- · 2018-12-31 10:03

I followed the most of the answers which was recommended here. First I got the following error:

fatal: unable to access 'https://github.com/folder/sample.git/': schannel: next InitializeSecurityContext failed: Unknown error (0x80092012) - The revocation function was unable to check revocation for the certificate.

Then I have tried the following command by @Salim Hamidi

git config --global http.proxy http://proxyuser:proxypwd@proxy.server.com:8080

But I got the following error:

fatal: unable to access 'https://github.com/folder/sample.git/': Received HTTP code 407 from proxy after CONNECT

This could happen if the proxy server can't verify the SSL certificate. So we want to make sure that the ssl verification is off (not recommended for non trusted sites), so I have done the following steps which was recommended by @Arpit but with slight changes:

1.First make sure to remove any previous proxy settings:

git config --global --unset http.proxy

2.Then list and get the gitconfig content

git config --list --show-origin

3.Last update the content of the gitconfig file as below:

[http]
sslCAInfo = C:/yourfolder/AppData/Local/Programs/Git/mingw64/ssl/certs/ca-bundle.crt
sslBackend = schannel
proxy = http://proxyuser:proxypwd@proxy.server.com:8080
sslverify = false
[https]
proxy = http://proxyuser:proxypwd@proxy.server.com:8080
sslverify = false
查看更多
登录 后发表回答