如何让Git使用代理服务器?
我需要从Git服务器签出代码,但它每次都显示“请求超时”。我该怎么解决这个问题呢?
或者如何设置代理服务器?
如何让Git使用代理服务器?
我需要从Git服务器签出代码,但它每次都显示“请求超时”。我该怎么解决这个问题呢?
或者如何设置代理服务器?
当前回答
尝试将以下内容放到~/。gitconfig文件:
[http]
proxy = http://proxy:8080
[https]
proxy = http://proxy:8080
[url "https://"]
insteadOf = 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
使用代理的另一种选择是使用SSH 在git配置中,在ssh地址上配置origin remote。然后使用ssh-keygen命令,它会给你一个公钥,你可以在你的GitLab或Gitab帐户设置和登录相应完成…
1-通过在git客户端中运行git remote -v来验证哪些遥控器正在使用。
2-如果这是http(s) url,将其更改为ssh地址,执行:git remote set-url <远程名称,例如origin> <新的ssh url > 例如
git remote set-url git@gitlab.com:example/myproject.git
3 .如果需要生成登录的SSH密钥,执行命令SSH -keygen -o,该命令生成public(id_rsa. key)。Pub文件)和私钥。
4份公钥内容。(从id_rsa。酒吧文件)
5-去gitlab/githup/....配置文件>设置/ssh-key。创建新的SSH密钥并粘贴公钥内容
使用命令:
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 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)。