简体   繁体   English

无法连接到 git 远程存储库

[英]Unable to connect to git remote repository

After performing git push -u origin master , I got:执行git push -u origin master ,我得到:

fatal: unable to access 'https://github.com/xxxx/xxxx.git': Failed to connect to 127.0.0.1 port 8087: Connection refused

Same error occurred, when I tried to clone other repositories, too.当我尝试克隆其他存储库时,也发生了同样的错误。

The Port 8087 doesn't seem to be busy.端口 8087 似乎并不忙。 What could go wrong?什么可能出错?

Edit: when I do clone from git:// instead of https:// , it works just fine.编辑:当我从git://而不是https://克隆时,它工作得很好。

This happens because a proxy is configured in git.发生这种情况是因为在 git 中配置了代理。

Since it's https proxy (and not http) git config http.proxy and git config --global http.proxy can't help.由于它是 https 代理(而不是 http),因此git config http.proxygit config --global http.proxy

1 : take a look at your git configuration 1:看一下你的git配置

git config --global -l

If you have nothing related to https proxy like https_proxy=... the problem is not here.如果您没有任何与 https 代理相关的内容,例如https_proxy=...问题不在这里。

If you have something related to https proxy then remove it from the file ~/.gitconfig and try again如果您有与 https 代理相关的内容,请将其从文件~/.gitconfig删除,然后~/.gitconfig

2 : if it still doesn't work, unset environment variables 2 : 如果它仍然不起作用,请取消设置环境变量

Check your environment variables :检查您的环境变量:

env|grep -i proxy  

You should have one or several lines with https_proxy=...您应该有一行或几行带有https_proxy=...

Unset one by one with : unset https_proxy (or HTTPS_PROXY depending of the name of the variable)一一unset https_proxyunset https_proxy (或 HTTPS_PROXY 取决于变量的名称)

3 : check environment variables again 3:再次检查环境变量

env|grep -i proxy

If it shows nothing you should be good.如果它什么也没显示,你应该很好。

Note : This solution can applies to http and https proxy problems.注意:此解决方案适用于 http 和 https 代理问题。 just the variables name changes from https to http只是变量名称从 https 更改为 http

Laurent's answer worked for me.洛朗的回答对我有用。 (I am behind corporate firewall.) In my case, (我在公司防火墙后面。)就我而言,

  • I removed the proxy setting in .gitconfig file.我删除了.gitconfig文件中的代理设置。

  • Everything just work fine.一切正常。 I can clone from a remote repo.我可以从远程仓库克隆。

  • When i wanted to push to the remote repo, I generated a ssh key .当我想推送到远程仓库时,我生成了一个ssh key Then I am able to push.然后我就可以推了。

Hope it saves someones 2 hours.希望它可以节省某人 2 小时。

git config --global --unset http.proxy

It seems that git tries to use a local proxy.似乎 git 尝试使用本地代理。

Please check your global network-settings and those of git.请检查您的全局网络设置和 git 的设置。

Use git config http.proxy and git config --global http.proxy to get the proxy-settings of git.使用git config http.proxygit config --global http.proxy来获取 git 的代理设置。

I had tried all the methods mentioned above, but I was missing something other than what they have mentioned,我已经尝试了上面提到的所有方法,但是除了他们提到的方法之外,我还遗漏了一些东西,

try to update your credentials in Control panel -> User Accounts -> Credential Manager for Git it worked for me尝试在“控制面板”->“用户帐户”->“Git 凭据管理器”中更新您的凭据,它对我有用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM