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

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

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


当前回答

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

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

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

其他回答

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

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

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

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

在终端上设置git代理

if

您不希望为每个git项目逐个手动设置代理 始终希望对所有项目使用相同的代理

全局设置一次

git config --global http.proxy username:password@proxy_url:proxy_port
git config --global https.proxy username:password@proxy_url:proxy_port

如果您只想为一个git项目设置代理 (在某些情况下,对于某些git连接,你可能不想使用相同的代理或任何代理)

//go to project root
cd /bla_bla/project_root
//set proxy for both http and https
git config http.proxy username:password@proxy_url:proxy_port
git config https.proxy username:password@proxy_url:proxy_port

如果要显示当前代理设置

git config --list 

如果要全局删除代理

git config --global --unset http.proxy
git config --global --unset https.proxy

如果您只想删除一个git根的代理

//go to project root
cd /bla-bla/project_root
git config --unset http.proxy
git config --unset https.proxy

下面是代理设置

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

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

#!/bin/sh

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

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

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

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