如何让Git使用代理服务器?
我需要从Git服务器签出代码,但它每次都显示“请求超时”。我该怎么解决这个问题呢?
或者如何设置代理服务器?
如何让Git使用代理服务器?
我需要从Git服务器签出代码,但它每次都显示“请求超时”。我该怎么解决这个问题呢?
或者如何设置代理服务器?
当前回答
除了这些答案,我发现考虑以下两点很有帮助:
可能需要强制一个身份验证方案:
[http]
# https://github.com/git/git/blob/master/Documentation/config.txt
proxyAuthMethod = anyauth|basic|digest|negotiate|ntlm
此外,通常使用NTLM身份验证模式时,可能需要显式地提供AD域。
在git bash中:
echo %userdomain%
并更新http。相应的代理:
git config --global http.proxy http://DOMAIN\\proxyuser:proxypwd@proxy.server.com:8080
无论如何,添加CURL日志可能有助于调查:
export GIT_CURL_VERBOSE=1
其他回答
作为使用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 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 config --global http.proxy http://username@proxy.example.com:PortNumber
请不要在命令中输入密码。当你尝试连接到任何git repo时,它会动态地询问。