使 Git 与代理服务器一起使用 - 因 “请求超时” 而失败

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

我需要从 Git 服务器中签出代码,但是每次都会显示 “请求超时”。我该如何解决?

另外,如何设置代理服务器?

答案

git config --global http.proxy http://proxyuser:proxypwd@proxy.server.com:8080
git config --global --unset http.proxy
git config --global --get http.proxy
$ 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

ProxyServer:Port的值设置一个名为http_proxy的系统变量。那是最简单的解决方案。分别使用https_proxy在注释中指出的 https_proxy。

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

参考: http : //bardofschool.blogspot.com/2008/11/use-git-behind-proxy.html

[http]
    proxy = http://username:password@proxy.at.your.org:8080
git -c "http.proxy=address:port" clone https://...
alias git-proxy='git -c "http.proxy=address:port"'
$ sudo apt-get install corkscrew
#!/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 $*
$ chmod +x git-proxy.sh
$ export GIT_PROXY_COMMAND="/<path>/git-proxy.sh"
git clone git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
git config --list --global --show-origin
[http]
    proxy = http://YOUR_PROXY_USERNAME:YOUR_PROXY_PASSWORD@YOUR.PROXY.SERVER:YOUR.PROXY.SERVER.PORT
    sslverify = false
[https]
    proxy = http://YOUR_PROXY_USERNAME:YOUR_PROXY_PASSWORD@YOUR.PROXY.SERVER:YOUR.PROXY.SERVER.PORT
    sslverify = false
[url "http://github.com/"]
    insteadOf = git://github.com/

[user]
    name = Arpit Aggarwal
    email = aggarwalarpit.89@gmail.com
[http]
    proxy = http://proxy:8080
[https]
    proxy = http://proxy:8080
[url "https://"]
    insteadOf = git://
#!/bin/sh

exec socat - socks4:your.company.com:$1:$2
git config --global http.proxy http://<proxy address>:<port number>
git clone git@github.com:<user name>/<project name>.git // will not use the http proxy