Git 推送:“fatal 'origin' 似乎不是 git 存储库 - 致命无法从远程存储库读取." [英] Git push: "fatal 'origin' does not appear to be a git repository - fatal Could not read from remote repository."

查看:53
本文介绍了Git 推送:“fatal 'origin' 似乎不是 git 存储库 - 致命无法从远程存储库读取."的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道已经有人问过类似的问题了.

I know similar questions have already been asked.

但是,我相信我的问题是由于我之前犯的错误造成的,因此有所不同:让我解释一下.

But, I believe my issue is due to a mistake I have previously made and therefore is different: let me explain.

一切都很顺利,尽我所能:

Everything was working smoothly, as I could:

  • git add . 我本地存储库中的所有文件.
  • git commit -m "message here" 将消息添加到我的提交中.
  • git push origin master 将我的文件上传到 GitHub.
  • git push heroku master 将我的文件上传到 Heroku.
  • git add . all the files from my local repository.
  • git commit -m "message here" to add messages to my commits.
  • git push origin master to upload my files to GitHub.
  • git push heroku master to upload my files to Heroku.

但是,在某些时候,我在本地创建了一个名为 add-calendar-model 的新分支,以防应用程序开发的后续步骤向南...

However, at some point, I created a new branch locally called add-calendar-model in case next steps of the app development would go south...

...这正是发生的事情.

... which is exactly what happened.

然而,尽管进行了多次尝试,我还是没有设法从 master 分支到我的本地存储库获取初始代码——即我创建新分支之前的代码.

However, despite many attempts, I did not manage to get the initial code — i.e. the code from before I created the new branch — from the master branch to my local repository.

因此,我决定手动删除本地存储库中的所有文件和 GitHub 中的 git clone 我的 master 分支.

So, I decided to manually delete all the files from my local repository and git clone my master branch from GitHub.

通过这种方式,我取回了所有文件,但现在,我无法再将任何文件推送到远程存储库.

This way, I got all my files back, but now, I cannot push any more to the remote repository.

每当我尝试运行 git push origin add-calendar-modelgit push origin master 时,我都会收到以下错误:

Any time I try to run git push origin add-calendar-model or git push origin master, I get the following error:

fatal: 'origin' does not appear to be a git repository
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

我对 Git 和 GitHub 不太熟悉,你现在可能已经猜到了,我不得不承认我不知道如何解决这个问题.

I am not very comfortable with Git and GitHub, as you may have guessed by now, and I have to admit that I have no clue about how to fix this.

有什么想法吗?

推荐答案

首先,检查您的 origin 是否通过运行设置

First, check that your origin is set by running

git remote -v

这应该会显示项目的所有推送/获取遥控器.

This should show you all of the push / fetch remotes for the project.

如果返回没有输出,跳到最后一个代码块.

验证远程名称/地址

如果返回显示您设置了遥控器,请检查遥控器的名称是否与您在命令中使用的遥控器匹配.

If this returns showing that you have remotes set, check that the name of the remote matches the remote you are using in your commands.

$git remote -v
myOrigin ssh://git@example.com:1234/myRepo.git (fetch)
myOrigin ssh://git@example.com:1234/myRepo.git (push)

# this will fail because `origin` is not set
$git push origin main

# you need to use
$git push myOrigin main

如果您想重命名遥控器或更改遥控器的 URL,您需要先删除旧遥控器,然后添加正确的遥控器.

If you want to rename the remote or change the remote's URL, you'll want to first remove the old remote, and then add the correct one.

移除旧遥控器

$git remote remove myOrigin

添加缺少的遥控器

然后您可以使用

$git remote add origin ssh://git@example.com:1234/myRepo.git

# this will now work as expected
$git push origin main

这篇关于Git 推送:“fatal 'origin' 似乎不是 git 存储库 - 致命无法从远程存储库读取."的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆