Git 推送 : "fatal ' origin' does not appear to be a git repository - fatal Could not read from remote repository."

标签 git github version-control branch

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

但是,我认为我的问题是由于我之前犯的一个错误,因此有所不同:让我解释一下。

一切都如我所愿顺利进行:

  • git add . 我本地存储库中的所有文件。
  • git commit -m "message here" 将消息添加到我的提交中。
  • git push origin master 将我的文件上传到 GitHub。
  • git push heroku master 将我的文件上传到 Heroku。

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

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

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

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

这样,我找回了所有文件,但现在,我无法再将任何内容推送到远程存储库。

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

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 不太满意,我不得不承认我不知道如何解决这个问题。

有什么想法吗?

最佳答案

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

git remote -v

这应该向您显示项目的所有推送/获取远程。

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

验证远程名称/地址

如果返回显示您已设置 Remote ,请检查 Remote 的名称是否与您在命令中使用的 Remote 相匹配。

$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

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

移除旧 Remote

$git remote remove myOrigin

添加缺失的 Remote

然后您可以使用添加正确的 Remote

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

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

关于Git 推送 : "fatal ' origin' does not appear to be a git repository - fatal Could not read from remote repository.",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32238616/

相关文章:

git - 本地 Gitlab 安装不显示所有提交

git - 如何确保提交作者

git - 如何在我的托管网络服务器上 check out git 标签

git - 无法 chdir 或不是 Git 存档

git - 无法创建工作树目录 'example.com'。 : Permission denied

svn - SVN在两个分支之间合并-“找不到路径”

git - GitFlow 工作流程中是否允许直接提交到 master 分支?

git - git 提供程序错误中不支持的 URL 协议(protocol)

git - 我如何使用 Github api 获取 pull 请求的审阅者列表?

github - 如何通过 GitHub API 获取存储库的分支数?