如何让Git使用代理服务器?
我需要从Git服务器签出代码,但它每次都显示“请求超时”。我该怎么解决这个问题呢?
或者如何设置代理服务器?
如何让Git使用代理服务器?
我需要从Git服务器签出代码,但它每次都显示“请求超时”。我该怎么解决这个问题呢?
或者如何设置代理服务器?
当前回答
对于git协议(git://…),安装socat并编写如下脚本:
#!/bin/sh
exec socat - socks4:your.company.com:$1:$2
使其可执行,将其放在您的路径和~/中。Gitconfig set core。Gitproxy到该脚本的名称。
其他回答
如果你正在使用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
设置一个名为http_proxy的系统变量,其值为“ProxyServer:Port”。 这是最简单的解决办法。分别使用daefu在评论中指出的https_proxy。
设置gitproxy(正如sleske提到的)是另一个选项,但这需要一个“命令”,它不像上面的解决方案那么简单。
引用: http://bardofschool.blogspot.com/2008/11/use-git-behind-proxy.html
我注意到一些事情,想在这里分享:
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协议(git://…),安装socat并编写如下脚本:
#!/bin/sh
exec socat - socks4:your.company.com:$1:$2
使其可执行,将其放在您的路径和~/中。Gitconfig set core。Gitproxy到该脚本的名称。
下面是代理设置
git config --global http.proxy http://<username>:<pass>@<ip>:<port>
git config --global https.proxy http://<username>:<pass>@<ip>:<port>