如何让Git使用代理服务器?
我需要从Git服务器签出代码,但它每次都显示“请求超时”。我该怎么解决这个问题呢?
或者如何设置代理服务器?
如何让Git使用代理服务器?
我需要从Git服务器签出代码,但它每次都显示“请求超时”。我该怎么解决这个问题呢?
或者如何设置代理服务器?
当前回答
使用命令:
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
其他回答
我遵循了这里推荐的大部分答案。首先,我得到了以下错误:
致命:无法访问 https://github.com/folder/sample.git/':频道:下一个 InitializeSecurityContext失败:未知错误(0x80092012) 属性的撤销功能无法检查 证书。
然后我尝试了@Salim Hamidi的以下命令
git config --global http.proxy http://proxyuser:proxypwd@proxy.server.com:8080
但我得到了以下错误:
致命:无法访问 'https://github.com/folder/sample.git/':接收到的HTTP代码 407从代理连接后
如果代理服务器无法验证SSL证书,就会发生这种情况。所以我们想要确保ssl验证是关闭的(不推荐用于不受信任的站点),所以我已经完成了以下步骤,这是@Arpit推荐的,但略有变化:
1.首先确保删除之前的所有代理设置:
git config --global --unset http.proxy
2.然后列出并获取gitconfig内容
git config --list --show-origin
3.最后更新gitconfig文件的内容如下:
[http]
sslCAInfo = C:/yourfolder/AppData/Local/Programs/Git/mingw64/ssl/certs/ca-bundle.crt
sslBackend = schannel
proxy = http://proxyuser:proxypwd@proxy.server.com:8080
sslverify = false
[https]
proxy = http://proxyuser:proxypwd@proxy.server.com:8080
sslverify = false
除了这些答案,我发现考虑以下两点很有帮助:
可能需要强制一个身份验证方案:
[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 Bash ssh-keygen.exe -t rsa -C 打开你的Git提供商(Github, Bitbucket等) 添加复制id_rsa。pub文件内容到Git提供者的输入页面(检查您的配置文件)
使用命令:
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
尝试将以下内容放到~/。gitconfig文件:
[http]
proxy = http://proxy:8080
[https]
proxy = http://proxy:8080
[url "https://"]
insteadOf = git://