如何让Git使用代理服务器?
我需要从Git服务器签出代码,但它每次都显示“请求超时”。我该怎么解决这个问题呢?
或者如何设置代理服务器?
如何让Git使用代理服务器?
我需要从Git服务器签出代码,但它每次都显示“请求超时”。我该怎么解决这个问题呢?
或者如何设置代理服务器?
当前回答
我注意到一些事情,想在这里分享:
git config --global http.proxy http://<proxy address>:<port number>
上述方法不适用于SSH url(即git@github.com:<用户名>/<项目名>.git):
git clone git@github.com:<user name>/<project name>.git // will not use the http proxy
如果我们将SSH设置为HTTPS端口(https://help.github.com/en/articles/using-ssh-over-the-https-port),事情也不会改变,因为它只改变了SSH连接连接的端口(默认为22)。
其他回答
如果你正在使用ubuntu,那么执行以下操作…
步骤1:安装开瓶器
$ sudo apt-get install corkscrew
步骤2:编写名为git-proxy.sh的脚本,并添加以下内容
#!/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 $*
步骤3:使脚本可执行
$ chmod +x git-proxy.sh
步骤4:通过设置环境变量为GIT设置代理命令
$ export GIT_PROXY_COMMAND="/<path>/git-proxy.sh"
现在使用git命令,例如
git clone git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
我遵循了这里推荐的大部分答案。首先,我得到了以下错误:
致命:无法访问 https://github.com/folder/sample.git/':频道:下一个 InitializeSecurityContext失败:未知错误(0x80092012) 属性的撤销功能无法检查 证书。
然后我尝试了@Salim Hamidi的以下命令
git config --global http.proxy http://proxyuser:proxypwd@proxy.server.com:8080
但我得到了以下错误:
致命:无法访问 'https://github.com/folder/sample.git/':接收到的HTTP代码 407从代理连接后
如果代理服务器无法验证SSL证书,就会发生这种情况。所以我们想要确保ssl验证是关闭的(不推荐用于不受信任的站点),所以我已经完成了以下步骤,这是@Arpit推荐的,但略有变化:
1.首先确保删除之前的所有代理设置:
git config --global --unset http.proxy
2.然后列出并获取gitconfig内容
git config --list --show-origin
3.最后更新gitconfig文件的内容如下:
[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
我注意到一些事情,想在这里分享:
git config --global http.proxy http://<proxy address>:<port number>
上述方法不适用于SSH url(即git@github.com:<用户名>/<项目名>.git):
git clone git@github.com:<user name>/<project name>.git // will not use the http proxy
如果我们将SSH设置为HTTPS端口(https://help.github.com/en/articles/using-ssh-over-the-https-port),事情也不会改变,因为它只改变了SSH连接连接的端口(默认为22)。
使用命令:
git config --global http.proxy http://proxyuser:proxypwd@proxy.server.com:8080
将proxyuser更改为代理用户 将proxypwd更改为您的代理密码 将proxy.server.com更改为代理服务器的URL 将8080更改为代理服务器上配置的代理端口
注意,这适用于http和https回购。
如果你决定在任何时候重置这个代理并在没有代理的情况下工作:
使用命令:
git config --global --unset http.proxy
最后,检查当前设置的代理:
git config --global --get http.proxy
我在公司使用Windows XP,所以我做了我的研究,在这里发现了这个,它对我有用。希望这对你有所帮助。
http_proxy环境变量
如果您使用代理服务器或防火墙,您可能需要设置http_proxy环境变量以便从命令行访问一些url。 例如:为perl安装ppm或在linux中应用rpm,更新ubuntu
将http_proxy变量设置为代理服务器的主机名或IP地址: http_proxy = http:// [proxy.example.org]
如果代理服务器需要用户名和密码,请以以下形式填写: http_proxy = http://(用户名:password@proxy.example.org)
如果代理服务器使用的端口号不是80,请填写端口号: http_proxy = http://(用户名:password@proxy.example.org: 8080)
Windows XP
打开控制面板并单击系统图标。 在“高级”选项卡上,单击“环境变量”。 单击“系统变量”面板中的“新建”。 添加带有适当代理信息的http_proxy(参见上面的示例)。
Linux、Solaris或HP-UX
使用特定于shell的命令(例如Set或export)设置http_proxy环境变量。要使此更改持久,请将该命令添加到shell的适当概要文件中。例如,在bash中,在.bash_profile或.bashrc文件中添加如下一行:
http_proxy = http://(用户名:password@hostname:端口); 出口美元http_proxy