如何让Git使用代理服务器?

我需要从Git服务器签出代码,但它每次都显示“请求超时”。我该怎么解决这个问题呢?

或者如何设置代理服务器?


当前回答

对于windows用户:如果git配置或设置http_proxy=不起作用,这个答案可能会有帮助:

将git存储库的git://协议替换为http://.注意,无论如何,你必须先设置http_proxy。

其他回答

使用命令:

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

下面是代理设置

git config --global http.proxy http://<username>:<pass>@<ip>:<port>
git config --global https.proxy http://<username>:<pass>@<ip>:<port>

尝试将以下内容放到~/。gitconfig文件:

[http]
    proxy = http://proxy:8080
[https]
    proxy = http://proxy:8080
[url "https://"]
    insteadOf = git://

如果您已经安装和配置了tsocks或proxychains,则可以

$ tsocks git clone <you_repository>

or

$ proxychains git clone <you_repository>

为了使它更短,我为proxychains创建了一个符号link /usr/bin/p,所以我可以像这样使用它

p git clone <you_repository>

我可以用它来代理任何命令

p <cmd-need-be-proxied>

顺便说一下,proxychains很长一段时间没有更新,你可能想试试proxychians-ng

设置一个名为http_proxy的系统变量,其值为“ProxyServer:Port”。 这是最简单的解决办法。分别使用daefu在评论中指出的https_proxy。

设置gitproxy(正如sleske提到的)是另一个选项,但这需要一个“命令”,它不像上面的解决方案那么简单。

引用: http://bardofschool.blogspot.com/2008/11/use-git-behind-proxy.html