如何设置 Git 通过代理

发布于 2024-12-09 12:08:54 字数 3090 浏览 0 评论 0原文

我想在工作中连接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/

,我还无法为 Git 提供等效的设置。

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

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

ssh github.com

,否则

ssh ssh.github.com

我会返回

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

我尝试过设置 http 和 https 代理。

这是 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

我也运行了

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

然后尝试克隆并获取。

$ 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

在我看来,我无法通过代理进行身份验证。不过,我使用的登录名和密码与通过 cURL 的 FTP 相同。

我怎样才能连接?

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

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.

I tried following instructions on Using Github Through Draconian Proxies under cygwin.

I've got corkscrew installed and tried to SSH to 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.

I've tried setting the http and https proxy.

Here is the output from 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.

How can I get connected?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

太阳哥哥 2024-12-16 12:08:55

我通常只需要设置:(

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

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

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

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)

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

囍孤女 2024-12-16 12:08:55

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

/home/usr/.curlrc

<块引用>

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

You can put proxy information in your ~/.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

够钟 2024-12-16 12:08:55

您不太可能能够通过代理通过 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

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

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

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.

落叶缤纷 2024-12-16 12:08:54

经过多次头痛之后,我终于偶然发现了 http://cntlm.sourceforge.net/。它是一个理解 ntlm 身份验证的代理代理。

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

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

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

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

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文