致命:'origin' 似乎不是 git 存储库

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

fatal: 'origin' does not appear to be a git repository

gitgithubpushgit-push

提问by xan

I've a repository moodleon my Github account which I forkedfrom the official repository.

moodle我的 Github 帐户上有一个forked来自官方存储库的存储库。

I then cloned it on my local machine. It worked fine. I created several branches (under the masterbranch). I made several commits and it worked fine.

然后我将它克隆到我的本地机器上。它工作得很好。我创建了几个分支(在master分支下)。我做了几次提交,效果很好。

I don't know how I'm getting the following error when I do : git push origin master

当我这样做时,我不知道如何收到以下错误: git push origin master

fatal: 'origin' does not appear to be a git repository
fatal: The remote end hung up unexpectedly

How do I resolve the error without effecting my repository on Github?

如何解决错误而不影响我在 Github 上的存储库?

I'm using Ubuntu 12.10

我正在使用 Ubuntu 12.10

The contents of my .git/configafter doing cat $(git rev-parse --show-toplevel)/.git/configgives:

.git/config做完后的内容cat $(git rev-parse --show-toplevel)/.git/config给出:

[core]
    repositoryformatversion = 0
    filemode = true
    bare = false
    logallrefupdates = true
[branch "master"]
[branch "MOODLE_23_STABLE"]
[branch "MOODLE_24_STABLE"]
[remote "upstream"]
    url = git://git.moodle.org/moodle.git
    fetch = +refs/heads/*:refs/remotes/upstream/*

回答by VonC

$HOME/.gitconfigis your globalconfig for git.
There are three levelsof config files.

$HOME/.gitconfig是您的 git全局配置。
三个级别配置文件

 cat $(git rev-parse --show-toplevel)/.git/config

(mentionedby bereal) is your localconfig, local to the repo you have cloned.

bereal提到的)是您的本地配置,是您克隆的存储库的本地配置。

you can also type from within your repo:

你也可以在你的 repo 中输入:

git remote -v

And see if there is any remote named 'origin' listed in it.

并查看其中是否列出了任何名为“origin”的遥控器。

If not, if that remote (which is created by default when cloning a repo) is missing, you can add it again:

如果没有,如果该远程(在克隆 repo 时默认创建)丢失,您可以再次添加它:

git remote add origin url/to/your/fork


The OP mentions:

OP提到:

Doing git remote -vgives:

git remote -v给:

upstream git://git.moodle.org/moodle.git (fetch) 
upstream git://git.moodle.org/moodle.git (push)

So 'origin' is missing: the reference to yourfork.
See "What is the difference between originand upstreamin github"

所以 ' origin' 丢失了:对你的叉子的引用。
参见“ githubin 有什么区别originupstream

enter image description here

在此处输入图片说明

回答by Aniket Thakur

I faced the same problem when I renamed my repository on GitHub. I tried to push at which point I got the error

当我在 GitHub 上重命名我的存储库时,我遇到了同样的问题。我试图推动,我得到了错误

fatal: 'origin' does not appear to be a git repository
fatal: The remote end hung up unexpectedly

I had to change the URL using

我不得不使用更改 URL

git remote set-url origin ssh://[email protected]/username/newRepoName.git

After this all commands started working fine. You can check the change by using

在此之后,所有命令都开始正常工作。您可以使用以下方法检查更改

git remote -v

In my case after successfull change it showed correct renamed repo in URL

在我的情况下,成功更改后,它在 URL 中显示了正确的重命名 repo

[aniket@alok Android]$ git remote -v
origin  ssh://[email protected]/aniket91/TicTacToe.git (fetch)
origin  ssh://[email protected]/aniket91/TicTacToe.git (push)

回答by sivi

It is possible the other branch you try to pull from is out of synch; so before adding and removing remote try to (if you are trying to pull from master)

您尝试从中提取的另一个分支可能不同步;所以在添加和删除远程尝试之前(如果您尝试从主服务器拉取)

git pull origin master

for me that simple call solved those error messages:

对我来说,这个简单的调用解决了这些错误消息:

  • fatal: 'master' does not appear to be a git repository
  • fatal: Could not read from remote repository.
  • 致命:'master' 似乎不是 git 存储库
  • 致命:无法从远程存储库读取。

回答by zdravko zdravkin

Try to create remote origin first, maybe is missing because you change name of the remote repo

尝试先创建远程源,可能因为您更改了远程存储库的名称而丢失

git remote add origin URL_TO_YOUR_REPO

git 远程添加源 URL_TO_YOUR_REPO

回答by Dohn Joe

This does not answer your question, but I faced a similar error message but due to a different reason. Allow me to make my post for the sake of information collection.

这不能回答您的问题,但由于不同的原因,我遇到了类似的错误消息。为了收集信息,请允许我发帖。

I have a git repo on a network drive. Let's call this network drive RAID. I cloned this repo on my local machine (LOCAL) and on my number crunching cluster (CRUNCHER). For convenience I mounted the user directory of my account on CRUNCHER on my local machine. So, I can manipulate files on CRUNCHER without the need to do the work in an SSH terminal.

我在网络驱动器上有一个 git repo。我们将此网络驱动器称为 RAID。我在我的本地机器 (LOCAL) 和我的数字运算集群 (CRUNCHER) 上克隆了这个 repo。为方便起见,我在本地机器上的 CRUNCHER 上安装了我帐户的用户目录。因此,我可以在 CRUNCHER 上操作文件,而无需在 SSH 终端中进行操作。

Today, I was modifying files in the repo on CRUNCHER via my local machine. At some point I decided to commit the files, so a did a commit. Adding the modified files and doing the commit worked as I expected, but when I called git pushI got an error message similar to the one posted in the question.

今天,我正在通过本地机器修改 CRUNCHER 上的 repo 中的文件。在某些时候我决定提交文件,所以提交了。添加修改后的文件并执行提交按我的预期工作,但是当我打电话时,git push我收到一条类似于问题中发布的错误消息。

The reason was, that I called pushfrom within the repo on CRUNCHER on LOCAL. So, all paths in the config file were plain wrong.

原因是,我push从本地 CRUNCHER 的 repo 中调用。因此,配置文件中的所有路径都是错误的。

When I realized my fault, I logged onto CRUNCHER via Terminal and was able to push the commit.

当我意识到我的错误时,我通过终端登录到 CRUNCHER 并能够推送提交。

Feel free to comment if my explanation can't be understood, or you find my post superfluous.

如果我的解释无法理解,或者您觉得我的帖子是多余的,请随时发表评论。

回答by Waqleh

I had the same error on git pull origin branchnamewhen setting the remote origin as path fsand not sshin .git/config:

.git/config中将远程源设置为路径fs而不是ssh 时,我在git pull origin branchname上遇到了同样的错误:

fatal: '/path/to/repo.git' does not appear to be a git repository 
fatal: The remote end hung up unexpectedly

It was like so (this only works for users on same server of gitthat have access to git):

就像这样(这仅适用于可以访问 git 的同一git服务器上的用户):

url = file:///path/to/repo.git/

Fixed it like so (this works on all users that have access to git user(ssh authorizes_keys or password)):

像这样修复它(这适用于有权访问git 用户(ssh authorizes_keys 或密码)的所有用户):

url = [email protected]:path/to/repo.git

the reason I had it as a directory path was because the gitfiles are on the same server.

我将它作为目录路径的原因是因为git文件在同一台服务器上。