如何设置Git来通过代理?

时间:2021-10-19 20:35:31

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使用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 -v -g——ftp-pasv——上传-文件MYFILE——代理PROXYADDRESS:PROXYPORT——代理-ntlm——代理-用户WINDOWSDOMAIN\ windows suser: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 Proxies under cygwin.

我试着按照指示在cygwin下使用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:提供或不知道主机名或servlet名。

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
user.email=someemail@gmail.com
github.user=ProggerPete
github.token=shouldprobablykeepthissecret
http.proxy=http://somedomain\someuser:somepass@10.167.116.142:80
https.proxy=http://somedomain\someuser:somepass@10.167.116.142:80

I've also run

我也跑

export https_proxy=http://somedomain\someuser:somepass@10.167.116.142:80
export http_proxy=http://somedomain\someuser:somepass@10.167.116.142:80
set https_proxy=http://somedomain\someuser:somepass@10.167.116.142:80
set http_proxy=http://somedomain\someuser:somepass@10.167.116.142:80

I then try and clone and get.

然后我尝试克隆并获得。

$ git clone https://ProggerPete@github.com/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?

我怎么联系上?

4 个解决方案

#1


29  

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.

我发现这很让人沮丧所以希望这能帮助其他的人。

#2


12  

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_proxy refers to the same http, not https, proxy address)

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

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

参见“git上的Http无法工作”。

#3


6  

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

您可以将代理信息放在您的~/.curlrc中:

/home/usr/.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

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

#4


2  

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://YOURNAME@github.com/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.

(如果不需要push access,请跳过第二行)。这一点,加上VonC提到的环境变量(https_proxy),将使您能够通过代理访问。

#1


29  

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.

我发现这很让人沮丧所以希望这能帮助其他的人。

#2


12  

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_proxy refers to the same http, not https, proxy address)

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

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

参见“git上的Http无法工作”。

#3


6  

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

您可以将代理信息放在您的~/.curlrc中:

/home/usr/.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

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

#4


2  

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://YOURNAME@github.com/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.

(如果不需要push access,请跳过第二行)。这一点,加上VonC提到的环境变量(https_proxy),将使您能够通过代理访问。