简体   繁体   English

git - 无法推送到远程,错误'致命:不是git存储库'

[英]git - can't push to remote, error 'fatal: Not a git repository'

I am having problems setting up Git with Github. 我在使用Github设置Git时遇到了问题。 I am following the instruction on the Rails tutorial online on their site, but I am getting a fatal error. 我在他们的网站上在线跟踪Rails教程的说明,但我收到致命的错误。 Now I want to remove the connection to see if that solves the problem, but its not letting me, keeps giving me a fatal error. 现在我想删除连接,看看是否解决了问题,但它不让我,不断给我一个致命的错误。 I did this: 我这样做了:

$ git remote add origin git@github.com:<myusername>/first_app.git
$ git push origin master

The error is: 错误是:

fatal: Not a git repository (or any of the parent directories): .git

first_app is already created on github, so i am confused. first_app已经在github上创建了,所以我很困惑。 Any ideas? 有任何想法吗?

First you need to have a local git repository for first_app: 首先,您需要为first_app创建一个本地git存储库:

  1. cd to /the/dir/with/first_app cd到/the/dir/with/first_app

  2. Create the git repository with: git init 使用: git init创建git存储库

    • This will create a 'hidden' .git/ directory which (basically) holds all the source controlled files that are checked in. 这将创建一个' .git/目录,它(基本上)保存所有签入的源控制文件。

Then git remote add to add the remote you want, then you can push the code to it (or pull from it). 然后git remote add添加你想要的遥控器,然后你可以将代码推送到它(或从中拉出)。

You can now think of the 'regular' visible files (the ones that existed in the directory before adding git) as working 'copies'. 您现在可以将“常规”可见文件(添加git之前存在于目录中的文件)视为工作“副本”。 The (full) file copies that are actually under .git/ are the ones being managed by source control, ie that is 'where' you are committing files 'to'. 实际位于.git/下的(完整)文件副本是由源代码控制管理的文件副本,即“将文件提交到'的位置”。 So when you add and commit a file it is the .git/ directory that is getting the file. 因此,当您添加并提交文件时,它是获取文件的.git/目录。 and when you then 'push' it, it goes to the remote. 然后当你“推”它时,它会转到遥控器。

Did you initialize a git repository in your local app? 你是否在本地应用程序中初始化了一个git存储库? The command is as follows. 命令如下。

git init 

Then you can add an origin, copying it from GitHub. 然后你可以添加一个原点,从GitHub复制它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM