如何设置 Git 通过代理

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7734518/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 12:03:08  来源:igfitidea点击:

How to set up Git to get through a proxy

gitproxygithubcygwin

提问by Peter Wilkinson

I want to connect to GitHub at work and need to get through the http proxy. I am able to get out for FTP using cURL using the command

我想在工作时连接到GitHub,需要通过http代理。我可以使用 cURL 使用命令退出 FTP

curl -v -g --ftp-pasv --upload-file MYFILE --proxy PROXYADDRESS:PROXYPORT --proxy-ntlm --proxy-user WINDOWSDOMAIN\WINDOWSUSER:WINDOWSPASSWORD ftp://FTPUSER:FTPPASS@FTPURL/

curl -v -g --ftp-pasv --upload-file MYFILE --proxy PROXYADDRESS:PROXYPORT --proxy-ntlm --proxy-user WINDOWSDOMAIN\WINDOWSUSER:WINDOWSPASSWORD ftp://FTPUSER:FTPPASS@FTPURL/

I've so far not been able to provide equivalent settings for Git.

到目前为止,我还无法为 Git 提供等效的设置。

I tried following instructions on Using Github Through Draconian Proxiesunder cygwin.

我尝试按照在 cygwin 下通过 Draconian 代理使用 Github 的说明进行操作。

I've got corkscrew installed and tried to SSH to GitHub

我已经安装了开瓶器并尝试通过 SSH 连接到 GitHub

ssh github.com

or

或者

ssh ssh.github.com

I get back

我回来了

ssh: Could not resolve hostname ssh.github.com: hostname nor servname provided, or not known.

ssh:无法解析主机名 ssh.github.com:提供的主机名或服务名,或未知。

I've tried setting the http and https proxy.

我试过设置 http 和 https 代理。

Here is the output from git --config -l

这是 git --config -l 的输出

core.symlinks=false
core.autocrlf=true
color.diff=auto
color.status=auto
color.branch=auto
color.interactive=true
pack.packsizelimit=2g
help.format=html
http.sslcainfo=C:/Program Files/Git/bin/curl-ca-bundle.crt
sendemail.smtpserver=/bin/msmtp.exe
diff.astextplain.textconv=astextplain
user.name=Peter Wilkinson
[email protected]
github.user=ProggerPete
github.token=shouldprobablykeepthissecret
http.proxy=http://somedomain\someuser:[email protected]:80
https.proxy=http://somedomain\someuser:[email protected]:80

I've also run

我也跑过

export https_proxy=http://somedomain\someuser:[email protected]:80
export http_proxy=http://somedomain\someuser:[email protected]:80
set https_proxy=http://somedomain\someuser:[email protected]:80
set http_proxy=http://somedomain\someuser:[email protected]:80

I then try and clone and get.

然后我尝试克隆并获取。

$ git clone https://[email protected]/project/JavaScript-Maven-Plugin.git
Cloning into JavaScript-Maven-Plugin...
Password:
error: The requested URL returned error: 407 while accessing https://ProggerPet
@github.com/project/JavaScript-Maven-Plugin.git/info/refs

fatal: HTTP request failed

This looks to me like I'm failing authentication with the proxy. However I'm using the same login and pass that works for FTP via cURL.

这在我看来就像我没有通过代理进行身份验证。但是,我使用的是通过 cURL 用于 FTP 的相同登录名和密码。

How can I get connected?

如何连接?

采纳答案by Peter Wilkinson

After much head bashing I finally stumbled across http://cntlm.sourceforge.net/. It's a proxy proxy that understands ntlm authentication.

经过一番猛烈抨击,我终于偶然发现了http://cntlm.sourceforge.net/。它是一个理解ntlm身份验证的代理代理。

I installed it and told it about the http proxy. Then pointed git at CNTLM and it all started working.

我安装了它并告诉它有关 http 代理的信息。然后将 git 指向 CNTLM,它就开始工作了。

I found getting this going very frustrating so hopefully this will help someone else in the same situation.

我发现这很令人沮丧,所以希望这能帮助处于相同情况的其他人。

回答by VonC

I usually only need to set:

我通常只需要设置:

set http_proxy=http://<login_internet>:<password_internet>@aproxy:aport
set https_proxy=http://<login_internet>:<password_internet>@aproxy:aport

(note the https_proxyrefers to the same http, not https, proxy address)

(注意https_proxy指的是同一个http,而不是 https ,代理地址)

See also "Cannot get Http on git to work".

另请参阅“无法在 git 上获取 Http 工作”。

回答by jeckhart

You can put proxy information in your ~/.curlrc:

你可以把代理信息放在你的 ~/.curlrc 中:

/home/usr/.curlrc

proxy = proxy.proxyhost.com:8443
proxy-user = user:pass
proxy-ntlm = true
noproxy = localhost,127.0.0.1,intraweb.company.com

/home/usr/.curlrc

proxy = proxy.proxyhost.com:8443
proxy-user = user:pass
proxy-ntlm = true
noproxy = localhost,127.0.0.1,intraweb.company.com

回答by patthoyts

You are unlikely to be able to get ssh to github tunnelled through your proxy. However as github provides https urls for all their repositories and you can push to that you don't need ssh. If you already have a repository checked out, you can change the url used with

您不太可能通过代理将 ssh 连接到 github。但是,由于 github 为其所有存储库提供了 https url,因此您可以推送到不需要 ssh 的位置。如果您已经签出存储库,则可以更改使用的 url

git remote set-url origin https://github.com/project/repo.git
git remote set-url --push origin https://[email protected]/project/repo.git

(skip the second line if you do not need push access). This, along with setting the environment variables (https_proxy) as mentioned by VonC will enable access via your proxy.

(如果您不需要推送访问,请跳过第二行)。这与 VonC 提到的设置环境变量 (https_proxy) 一起将启用通过您的代理进行访问。