Search code examples
ruby-on-railsmacosgitgithubgit-push

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


I am having problems setting up Git with Github. I am following the instruction on the Rails tutorial online on their site, but I am getting a fatal error. 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. Any ideas?


Solution

  • First you need to have a local git repository for first_app:

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

    2. Create the git repository with: git init

      • This will create a 'hidden' .git/ directory which (basically) holds all the source controlled files that are checked in.

    Then git remote add to add the remote you want, then you can push the code to it (or pull from it).

    You can now think of the 'regular' visible files (the ones that existed in the directory before adding git) as working 'copies'. The (full) file copies that are actually under .git/ are the ones being managed by source control, i.e. that is 'where' you are committing files 'to'. So when you add and commit a file it is the .git/ directory that is getting the file. and when you then 'push' it, it goes to the remote.