致命:无法连接到 github.com:github.com[0: 140.82.121.4]: errno=Unknown error

问题描述 投票:0回答:5

我的 Git 帐户有问题。每次执行

git push
,都会出现以下错误:

Git push error

我发现我正在使用 SSH URL:

SSH URL

我尝试使用以下命令切换回 HTTPS URL:

git config --global url.https://github.com/.insteadOf git://github.com/
git config --global url."https://".insteadOf git://

然而,它似乎并没有改变任何东西: example

我尝试了很多我认为是解决方案的选项,例如手动配置配置文件,但没有任何效果。

git git-push git-remote
5个回答
26
投票

出现这个错误是因为你的git端口被限制了
因此,您可以使用以下命令修复它:

git config --global url.https://github.com/.insteadOf git://github.com/

通过在全球范围内执行此操作,它还将修复其他问题,其中旧存储库或其他场景可能正在使用

git
而不是
https
,当
git://
端口/协议现在与之前相比可能无法运行时。

如果对您有用,请点赞!
谢谢。


1
投票

要将

git
ssh
一起使用,需要不同的 url 语法,将
git@<url>
作为 url。 根据您的屏幕截图,网址很可能看起来像这样

[email protected]:ahlemtbini/blog_web.git

您可以使用以下命令更改它

git remote set-url origin [email protected]:ahlemtbini/blog_web.git

如果您正在使用

github
,我建议您始终使用该存储库
code
-页面上
github
-按钮下列出的url。 更多信息在这里

有关 git 使用的协议的更多信息,请阅读有关 git 服务器协议 的页面。


1
投票

所以我认为这里发生了一些事情:

  1. 第一个屏幕截图的错误看起来可能是由于使用不执行任何类型的身份验证/授权的普通

    git://
    协议克隆存储库引起的。意思是你可以
    git pull
    但你不能
    git push
    .

  2. 如果你想更新你的 git 配置以在推送时自动使用

    https
    ,你可以在你的 gitconfig 中添加这样的东西:

[url "https://github.com/"]
    pushInsteadOf = git://github.com/
  1. 或者,如果您想使用 SSH 而不是
    git://
    https://
    协议(并将您的公钥上传到您的 GH 帐户),您可以添加
[url "[email protected]:"]
    pushInsteadOf = git://github.com/
    pushInsteadOf = https://github.com/


1
投票

我在运行时遇到了这个错误

git submodule update --init
.

我通过将我所有的

git://
子模块更改为
https://
文件中的
.gitmodules
子模块来解决问题。

然后我跑了

git submodule sync

在那之后我的子模块更新工作正常。


1
投票

在我的例子中,我发现我的 flutter 项目试图从 pubspec.yaml 上的 URL 获取依赖项,格式如下:“git:github.com/repository”...为了修复它,我只需要更改“git”代表“https”。

© www.soinside.com 2019 - 2024. All rights reserved.