Git 推送:“fatal 'origin' 似乎不是 git 存储库 - 致命无法从远程存储库读取。”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/32238616/
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-09 03:31:25  来源:igfitidea点击:

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

gitgithubversion-controlbranch

提问by Thibaud Clement

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

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

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

... which is exactly what happened.

……这正是发生的事情。

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 masterbranch to my local repository.

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

So, I decided to manually delete all the files from my local repository and git clonemy masterbranch from GitHub.

所以,我决定从我的本地存储库和git clone我的masterGitHub 分支中手动删除所有文件。

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

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

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

每当我尝试运行git push origin add-calendar-model或 时git 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.

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.

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

Any idea?

任何的想法?

回答by Matt Clark

First, check that your originis set by running

首先,通过运行检查您的原点是否已设置

git remote -v

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

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

If this returns with no output, skip to last code block.

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

Verify remote name / address

验证远程名称/地址

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://[email protected]:1234/myRepo.git (fetch)
myOrigin ssh://[email protected]:1234/myRepo.git (push)

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

# you need to use
$git push myOrigin master

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.

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

Remove the old remote

移除旧遥控器

$git remote remove myOrigin

Add missing remote

添加缺少的遥控器

You can then add in the proper remote using

然后,您可以使用添加正确的遥控器

$git remote add origin ssh://[email protected]:1234/myRepo.git

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

回答by heb-NR

As Matt Clark stated above

正如马特克拉克上面所说

However, origin might not be set, so skip the deleting step and simply attempting to add can clear this up.

但是,可能未设置原点,因此跳过删除步骤,只需尝试添加即可清除此问题。

git remote add origin <"clone">

Where "clone" is simply going into your GitHub repo and copying the "HTTPS clone URL" and pasting into GitBash

其中“克隆”只是进入您的 GitHub 存储库并复制“HTTPS 克隆 URL”并粘贴到 GitBash

回答by Magere

Make sure the config file at .git is correct...Check URL & Make sure your using the correct protocol for your keys ...ProjectWorkspace/.git/config

确保 .git 中的配置文件是正确的...检查 URL 并确保您对密钥使用正确的协议...ProjectWorkspace/.git/config

  ~Wrong url for git@bitbucket
[core]
    repositoryformatversion = 0
    filemode = true
    bare = false
    logallrefupdates = true
[remote "origin"]
    url = gitbucket.org:Prezyack/project-one-hello.git
    fetch = +refs/heads/*:refs/remotes/origin/*

 ~Wrong URL for SSH...
[core]
    repositoryformatversion = 0
    filemode = true
    bare = false
    logallrefupdates = true
    ignorecase = true
    precomposeunicode = true
[remote "origin"]
    fetch = +refs/heads/*:refs/remotes/origin/*
    url = https://[email protected]/emmap1/bitbucketspacestation.git
[branch "master"]
    remote = origin
    merge = refs/heads/master

We are looking at the URL... e.g: For bitbucket, expect [email protected] its gitbucket.org. make the necessary changes.. SAVE Try pushing again.

我们正在查看 URL... 例如:对于 bitbucket,期望 [email protected]....如果它是 gitbucket.org。进行必要的更改.. SAVE 再次尝试推送。

回答by Nikhil Shrivastav

A similar error appears while pulling the changes from the origin. If you are trying in Intellij from the menu options, the pull might not work directly.

从原点提取更改时会出现类似的错误。如果您从菜单选项中尝试使用 Intellij,则拉取可能无法直接工作。

Go to terminal and type this command and this should work out: git pull origin master

转到终端并输入此命令,这应该可以解决:git pull origin master

回答by Beaug45

I had the same issue. When I checked my config file I noticed that 'fetch = +refs/heads/:refs/remotes/origin/' was on the same line as 'url = Z:/GIT/REPOS/SEL.git' as shown:

我遇到过同样的问题。当我检查我的配置文件时,我注意到 'fetch = +refs/heads/ :refs/remotes/origin/' 与 'url = Z:/GIT/REPOS/SEL.git' 在同一行,如图所示:

[core]
    repositoryformatversion = 0
    filemode = false
    bare = false
    logallrefupdates = true
    symlinks = false
    ignorecase = true
[remote "origin"]
    url = Z:/GIT/REPOS/SEL.git     fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
    remote = origin
    merge = refs/heads/master
[gui]
    wmstate = normal
    geometry = 1109x563+32+32 216 255

At first I did not think that this would have mattered but after seeing the post by Magere I moved the line and that fixed the problem:

起初我不认为这会很重要,但在看到 Magere 的帖子后,我移动了线路并解决了问题:

[core]
    repositoryformatversion = 0
    filemode = false
    bare = false
    logallrefupdates = true
    symlinks = false
    ignorecase = true
[remote "origin"]
    url = Z:/GIT/REPOS/SEL.git
    fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
    remote = origin
    merge = refs/heads/master
[gui]
    wmstate = normal
    geometry = 1109x563+32+32 216 255

回答by md sha

if you add your remote repository by using git clone then follow the steps:-

如果您使用 git clone 添加远程存储库,请按照以下步骤操作:-

git clone <repo_url>then

git clone <repo_url>然后

git init

git init

git add **means add all files

git add **表示添加所有文件

git commit -m 'your commit'

git commit -m 'your commit'

git remote -vfor check any branch run or not if not then nothing show then we add or fetch the repository. "fetch first". You need to rungit pull origin <branch>or git pull -r origin <branch>before a next push.

git remote -v检查是否有任何分支运行,如果没有,则没有显示,然后我们添加或获取存储库。“先取”。您需要运行git pull origin <branch>在下一次 pushgit pull -r origin <branch>之前。

then

然后

git remote add origin <git url>
 git pull -r origin master
git push -u origin master```

回答by vsriram92

Sometimes you don't have a local REF for pushing that branch back to the origin.
Try

有时您没有本地 REF 来将该分支推回原点。
尝试

git push origin master:master

This explicitly indicates which branch to push to (and from)

这明确指示要推送到(和从)哪个分支