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

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

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


当前回答

对于git协议(git://…),安装socat并编写如下脚本:

#!/bin/sh

exec socat - socks4:your.company.com:$1:$2

使其可执行,将其放在您的路径和~/中。Gitconfig set core。Gitproxy到该脚本的名称。

其他回答

使用命令:

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用户:如果git配置或设置http_proxy=不起作用,这个答案可能会有帮助:

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

作为使用git配置的替代方案——global http。代理地址:端口,可以在命令行设置代理:

git -c "http.proxy=address:port" clone https://...

优点是代理不需要持久设置。在Bash下你可以设置一个别名:

alias git-proxy='git -c "http.proxy=address:port"'

如果配置代理服务器的命令行方式不起作用, 你可能只需要编辑.gitconfig(在你的配置文件的根目录中,它可能隐藏在C:\Documents and Settings和一些网络驱动器中)并添加以下内容:

[http]
    proxy = http://username:password@proxy.at.your.org:8080

但是,YMMV只包含命令行配置的第一步。你可能也需要编辑系统git配置,我不知道他们把它藏在哪里。

如果你正在使用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