如何让Git使用代理服务器?
我需要从Git服务器签出代码,但它每次都显示“请求超时”。我该怎么解决这个问题呢?
或者如何设置代理服务器?
如何让Git使用代理服务器?
我需要从Git服务器签出代码,但它每次都显示“请求超时”。我该怎么解决这个问题呢?
或者如何设置代理服务器?
当前回答
设置一个名为http_proxy的系统变量,其值为“ProxyServer:Port”。 这是最简单的解决办法。分别使用daefu在评论中指出的https_proxy。
设置gitproxy(正如sleske提到的)是另一个选项,但这需要一个“命令”,它不像上面的解决方案那么简单。
引用: http://bardofschool.blogspot.com/2008/11/use-git-behind-proxy.html
其他回答
这对我来说是可行的,在公司防火墙后面的windows XP系统中。
我不需要安装任何本地代理或任何其他软件,除了git v1.771从http://code.google.com/p/msysgit/downloads/list?can=3
$ git config --global http.proxy http://proxyuser:proxypwd@proxy.server.com:8080
$ git config --system http.sslcainfo /bin/curl-ca-bundle.crt
$ git remote add origin https://mygithubuser:mygithubpwd@github.com/repoUser/repoName.git
$ git push origin master
proxyuser=我们IT部门分配给我的代理用户,在我的情况下,它是我用来登录我的PC的同一个windows用户,Active Directory用户
Proxypwd =我的代理用户密码
proxy.server.com:8080 =代理名称和端口,我从控制面板,互联网选项,连接,局域网设置按钮,代理服务器部分内的高级按钮,使用第一行(http)上的服务器名和端口。
mygithubuser =我用来登录github.com的用户
Mygithubpwd =我的github.com用户密码
repoUser = repo的用户所有者
repoName = repo的名称
我遵循了这里推荐的大部分答案。首先,我得到了以下错误:
致命:无法访问 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://<username>:<pass>@<ip>:<port>
git config --global https.proxy http://<username>:<pass>@<ip>:<port>
如果你正在使用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
对于windows用户:如果git配置或设置http_proxy=不起作用,这个答案可能会有帮助:
将git存储库的git://协议替换为http://.注意,无论如何,你必须先设置http_proxy。