git git错误:访问时无法连接到主机

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11890740/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 14:21:30  来源:igfitidea点击:

git error: couldn't connect to host while accessing

git

提问by user717787

Am getting the following error while trying to pull/push or create new-clone

尝试拉/推或创建新克隆时出现以下错误

error: couldn't connect to host while accessing https://github.com/user/pack.git/info/refsfatal: HTTP request failed

错误:访问https://github.com/user/pack.git/info/refs 时无法连接到主机 致命:HTTP 请求失败

when i googled, people suggested to setup http_proxy.. but i don't understand it or i don't know to setup it.. am totally stuck up with it..

当我用谷歌搜索时,人们建议设置 http_proxy .. 但我不明白它或者我不知道设置它.. 我完全坚持它..

i don't know how to overcome these issues..

我不知道如何克服这些问题..

any help would be appreciated..

任何帮助,将不胜感激..

NB: note that i was able to use git before couple of days.. in the last couple of days it has been screwed up.. please help..

注意:请注意,我能够在几天前使用 git.. 在过去的几天里,它被搞砸了.. 请帮忙..

回答by jlcj

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

works for me

对我来说有效

回答by Bill Paetzke

This happened to me on my Vagrant VirtualBox VM running Ubuntu 12.04. The vagrant instance had been up for several days. I restarted the VM (vagrant reload), ssh'd back in, and it worked.

这发生在我运行 Ubuntu 12.04 的 Vagrant VirtualBox VM 上。vagrant 实例已经运行了好几天。我重新启动了虚拟机 ( vagrant reload),ssh 重新进入,它工作正常。

What's the cause? Not sure. Someone else can speculate. However, I always like to reboot three timesjust to be sure ;)

原因是什么?没有把握。别人可以推测。但是,我总是喜欢重新启动三遍以确保;)

回答by Nobu

I've faced the same error when I changed the network that my laptop was connected. Editing /etc/resolv.conf properly solved the problem:

当我更改笔记本电脑连接的网络时,我遇到了同样的错误。正确编辑 /etc/resolv.conf 解决了问题:

nameserver 8.8.8.8

Making resolv.conf blank and reboot might solve it too.

将 resolv.conf 设置为空白并重新启动也可以解决它。

On debian 2.6.32-5-amd64 + VirtualBox 4.2.12.

在 debian 2.6.32-5-amd64 + VirtualBox 4.2.12 上。

回答by Vivek S

I gave the follwoing command to restart my network services. This would work for sure:

我给出了以下命令来重新启动我的网络服务。这肯定会起作用:

service network restart

回答by jetbird13

I have experienced the same error when wanted to push code on github. The problem was that I had messed up some environment variables on my Ubuntu machine. This happened because I wanted to use a manual proxy on google chrome.

当我想在 github 上推送代码时,我遇到了同样的错误。问题是我弄乱了我的 Ubuntu 机器上的一些环境变量。发生这种情况是因为我想在 google chrome 上使用手动代理。

If you are using linux use the following command to see if http_proxyand https_proxyare set to some ip address.

如果您使用的是 linux,请使用以下命令查看http_proxyhttps_proxy是否设置为某个 ip 地址。

env | grep http_proxy

Then use the following commands to unsetthe value of these two variables.

然后使用下面的命令来unset获取这两个变量的值。

unset http_proxy
unset https_proxy

Try to use git again. If it does not work then do a reboot. It worked for me.

再次尝试使用 git。如果它不起作用然后重新启动。它对我有用。

回答by Christopher

One solution, if this is a repository under you control, would be to use an SSH keyfor your repository access instead of HTTP. Update your remote accordingly by dropping the originremote with:

如果这是您控制的存储库,则一种解决方案是使用SSH 密钥而不是 HTTP 访问存储库。通过删除origin遥控器相应地更新您的遥控器:

git remote rm origin
git remote add origin <ssh_path_from_github>

You can find the ssh path in github here:

您可以在 github 中找到 ssh 路径:

SSH github access

SSH github 访问

Make sure to preface it with ssh://when you re-add the remote. If this doesn't work then we'll look at the http proxy settings, but based on your faux github link, I'm hoping it's a repository under your control.

ssh://重新添加遥控器时,请确保以它为开头。如果这不起作用,那么我们将查看 http 代理设置,但基于您的人造 github 链接,我希望它是您控制下的存储库。

回答by macsplean

My extremely simple solution was to first clone the empty new repo. I then deleted the .git folder in my project and moved all my project files & folders into the new repo folder. I then changed directories into that folder and then ran the add, commit, and pushcommands. Everything worked well.

我非常简单的解决方案是首先克隆空的新仓库。然后我删除了项目中的 .git 文件夹,并将我所有的项目文件和文件夹移动到新的 repo 文件夹中。后来我改变目录到该文件夹,然后跑了addcommitpush命令。一切都运行良好。

Before trying this solution, I had not cloned the git repo first. My project folder and the repo had the same name, I had run git init, add, commit, and set the upstream, but pushwas giving me an error (failure to connect to host).

在尝试这个解决方案之前,我没有先克隆 git repo。我的项目文件夹和 repo 具有相同的名称,我运行了git init, add,commit并设置了上游,但是push给了我一个错误(无法连接到主机)。

回答by Leniel Maccaferri

I was getting a similar error in Visual Studio 2013:

我在 Visual Studio 2013 中遇到了类似的错误:

An error occurred. Detailed message: An error was raised by libgit2. Category = Net (Error).
An error occurred while sending the request.

Then I tried using Git GUI:

然后我尝试使用 Git GUI:

Pushing to https://[email protected]/myrepo/bhp.git
error: Couldn't resolve host 'bitbucket.org' while accessing https://[email protected]/myrepo/bhp.git/info/refs?service=git-receive-pack
fatal: HTTP request failed

Guess what... my Parallels Virtual Machinehad no internet connection at the moment. After reestablishing the internet connection I could push my commit. :) Can't believe that happened. We're so used to have an internet connection always on.

你猜怎么着……我Parallels Virtual Machine现在没有互联网连接。重新建立互联网连接后,我可以推送我的提交。:) 不敢相信发生了。我们习惯于始终保持互联网连接。

回答by Pavel Evstigneev

I got same error when try to pull using different linux user.

尝试使用不同的 linux 用户进行拉取时出现相同的错误。

ls -lah
whoami

Make sure current user is same as owner of that folder.

确保当前用户与该文件夹的所有者相同。