为什么我在代理下无法克隆此 GitHub 存储库?

Why I can't clone this GitHub repository when I am under a proxy?

我是 Git 和 GitHub 的新手,我想我有一些配置问题。

昨天我已经正确配置了本地 GIT 和 GitHub 帐户之间的 SSH 连接。它工作正常。

今天我去了我在代理下的办公室,并使用同一台笔记本电脑尝试将远程存储库(在我的 GitHub 帐户上)克隆到我的本地存储库。

在我的 Git 上正确设置了代理,实际上在做:

$ git config --global http.proxy
http://XX.YY.ZZ.AAA:3228

这是我在浏览器设置中设置的用于浏览 Internet 的同一个代理。

问题是,当我尝试将我在 GitHub 上的存储库克隆到我的本地存储库时,我收到此错误消息:

$ git clone git@github.com:AndreaNobili/recipes.git
Cloning into 'recipes'...
ssh: connect to host github.com port 22: Connection timed out
fatal: Could not read from remote repository.

如果我使用我的智能手机连接(不在代理下)连接到互联网,它工作正常。

为什么?我错过了什么?

看起来您需要将环境变量设置为 http_proxy,因为 curllibcurl 似乎无法识别大写变量 HTTP_PROXY.

This link 详细说明:

The variable "HTTP_PROXY", using all caps, is no longer permitted/understood (since 7.7.2 actually).

Here's why: When CGI scripts get executed from within web servers, they usually get environment variables set before the script is executed. Headers in the incoming request that activate the script get converted to variables named HTTP_[header].

So, if anyone wrote a CGI script that in turn was using curl, you could actually trick curl to use a http proxy of your choice by passing a 'Proxy: [yada yada]' header.

http_proxy', using lower case, on the other hand is perfectly understood by curl.

虽然您已经配置了一个 http 代理,但是您没有指示 Git 使用 http - 您已经指定它应该使用 ssh 来连接:

$ git clone git@github.com:AndreaNobili/recipes.git

确实,您的错误消息是 ssh 超时:

ssh: connect to host github.com port 22: Connection timed out

发生这种情况是因为您的防火墙阻止了您的连接。相反,将存储库指定为 HTTP URL,Git 将使用您配置的企业代理:

$ git clone https://github.com/AndreaNobili/recipes.git