origin 似乎不是 git 存储库

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

origin does not appear to be a git repository

gitgithubrepository

提问by Marlo

I created a new repository online at github, where i have an account. The project is at, say:

我在 github 上在线创建了一个新存储库,我在那里有一个帐户。该项目位于,例如:

https://github.com/myname/myproject

https://github.com/myname/myproject

Now I want to add, commit and push things to that project from my file system. So I opened the terminal on Ubuntu, went to the directory that I want to make into a git folder and typed git init

现在我想从我的文件系统向该项目添加、提交和推送内容。所以我在 Ubuntu 上打开终端,进入我想放入 git 文件夹的目录并输入 git init

    ~/myfolder$ git init

then I typed

然后我打字

    ~/myfolder$ git clone [email protected]:myname/myproject.git

then I typed git status, to find that a whole lot of files are untracked. So I added one of them, like

然后我输入 git status,发现一大堆文件没有被跟踪。所以我添加了其中之一,比如

    ~/myfolder/mysubfolder$ git add subfolderfile.txt

I even committed by

我什至犯了

    ~/myfolder/mysubfolder$ git commit -m "Some comment"

but then pushing it

但然后推动它

    ~/myfolder/mysubfolder$ git push origin master

gives

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.

致命:'origin' 似乎不是 git 存储库致命:无法从远程存储库读取。请确保您拥有正确的访问权限并且存储库存在。

I read other questions on this forum but my level of coding sophistication is that of your average grandma, so I tried

我在此论坛上阅读了其他问题,但我的编码复杂程度与您的普通祖母相同,所以我尝试了

    $ git remote set-url origin [email protected]:myname/myproject.git

but that didn't work: No such remote 'origin'. I am really at a loss. Please explain in greatgrandpa style what I need to do. Prior knowledge=0. E.g I'd prefer "the big black window" over the Terminal or else I'd be very happy to have a brief explanation of what it is. Thanks so much.

但这不起作用:没有这样的远程 'origin'。我真的很茫然。请用曾祖父的方式解释我需要做什么。先验知识=0。例如,我更喜欢终端上的“大黑窗”,否则我很乐意简要说明它是什么。非常感谢。

回答by rdgd

The issue here is almost certainly caused by you running git initfirst and then cloning your project into the same directory using the git clonecommand. And even if you can fix the issue by adding the remote to the empty repository that you initialized on your machine, you don't want to do that because you will then have two git repositories, one nested inside the other.

这里的问题几乎肯定是由您git init先运行然后使用该git clone命令将项目克隆到同一目录引起的。即使您可以通过将远程添加到您在机器上初始化的空存储库来解决问题,您也不想这样做,因为您将有两个 git 存储库,一个嵌套在另一个中。

Because of the above, if you don't have any valuable changes in the project on your local machine, it would make things more simple to just blow away all the contents of your ~/myfolder/dir and re-clone the project by doing the following:

由于上述原因,如果您在本地机器上的项目中没有任何有价值的更改,那么只需~/myfolder/通过执行以下操作清除目录中的所有内容并重新克隆项目,事情就会变得更加简单:

rm -rf ~/myfolder
git clone [email protected]:myname/myproject.git ~/myfolder

If you have changes that you want to preserve in your project located at ~/myfolder/mysubfolder, then we can just move stuff around to make sure that you don't lose anything. I would recommend first that you do the following to get rid of the nesting:

如果您希望在位于 的项目中保留更改~/myfolder/mysubfolder,那么我们可以移动一些内容以确保您不会丢失任何内容。我首先建议您执行以下操作来消除嵌套:

cd ~/myfolder
rm -rf .git
mv mysubfolder/* .

At this point, you should have all of your project's files and .gitfolder the mysubfolder/directory. Which you can check with ls -al

此时,您应该拥有项目的所有文件和.git文件夹mysubfolder/目录。你可以检查ls -al

Next we want to check that you have a remote repository properly configured. To do so, run the command git remote -vhopefully you will see the following output:

接下来我们要检查您是否正确配置了远程存储库。为此,请运行该命令,git remote -v希望您会看到以下输出:

origin  [email protected]:myname/myproject.git (fetch)
origin  [email protected]:myname/myproject.git (push)

If you don't see the output above, don't have any fear, quick fix. Just run the command:

如果您没有看到上面的输出,请不要害怕,快速修复。只需运行命令:

git remote add origin [email protected]:myname/myproject.git

At this point we have a reasonable directory structure and the remote repository properly configured for you. Now it's a matter of having access to that remote repository. Since the way you set it up originally was over ssh, the best option, and that's what I've shown you how to do so far, we are going to continue down that path.

此时我们有一个合理的目录结构和为您正确配置的远程存储库。现在是访问该远程存储库的问题。由于您最初设置它的方式是通过 ssh,这是最好的选择,这就是我到目前为止向您展示的方法,我们将继续沿着这条路走下去。

First we need to check that you do have a keypair, so do the following:

首先,我们需要检查您是否有密钥对,因此请执行以下操作:

cd ~/.ssh
ls

If you have a keypair then I would expect to see the two files id_rsaand id_rsa.pub. If you don't have those files (although sometimes they are named differently), then do the following

如果您有密钥对,那么我希望看到两个文件id_rsaid_rsa.pub. 如果您没有这些文件(尽管有时它们的名称不同),请执行以下操作

ssh-keygen -t rsa
ls

Now you should have those files. id_rsais your private key, which you don't want to leave your computer and should never be shared with anyone, but id_rsa.pubis you public key, which is a way that other people and services know how to identify you. We need to make sure that your github account has you public key id_rsa.pubadded to it. So now do the following:

现在您应该拥有这些文件。id_rsa是你的私钥,你不想离开你的电脑,永远不应该与任何人共享,而是id_rsa.pub你的公钥,这是其他人和服务知道如何识别你的方式。我们需要确保您的 github 帐户中id_rsa.pub添加了您的公钥。所以现在执行以下操作:

  1. login to github
  2. Navigate to https://github.com/settings/keys
  3. Click the button "New SSH key"
  4. Give it a name like "Home Desktop" or "Work laptop"
  5. Copy the contents of the file id_rsa.pub
  6. Paste the contents of that file into the key field in github
  7. Click the "Add SSH Key" button
  1. 登录github
  2. 导航到https://github.com/settings/keys
  3. 单击“新建 SSH 密钥”按钮
  4. 给它起一个像“家用桌面”或“工作笔记本电脑”这样的名字
  5. 复制文件内容 id_rsa.pub
  6. 将该文件的内容粘贴到 github 中的关键字段中
  7. 单击“添加 SSH 密钥”按钮

Now you should have no trouble at all push and pulling from your remote repository.

现在,您应该可以轻松地从远程存储库中进行推送和拉取操作了。

回答by ALinuxLover

Try using https://github.com/myname/myproject.
If this doesn't work, make sure you are signed in to the Git account you used to create the online repo. git config --global your.nameand git config --global your.emailshould do the job.
I hope this helps!

尝试使用https://github.com/myname/myproject.
如果这不起作用,请确保您已登录用于创建在线存储库的 Git 帐户。git config --global your.name并且git config --global your.email应该完成这项工作。
我希望这有帮助!

EDIT: Are you using a branch of Debian? E.G. Raspbian, Ubuntu, etc.
If so, you should be able to run sudo apt-get install git-gui. After that, in your desktop, you should have a new app that says something like "Git". Open that and you should have a graphical interface, if you prefer that ;)

编辑:您使用的是 Debian 的一个分支吗?EG Raspbian、Ubuntu 等。
如果是这样,您应该能够运行sudo apt-get install git-gui. 之后,在您的桌面上,您应该有一个新的应用程序,上面写着类似“Git”的内容。打开它,你应该有一个图形界面,如果你愿意的话;)