12

I'm following along with the railstutorial.org, and when I get to the "git push heroku master" part, I get the following error:

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

So I do some googling, and see a common troubleshooting trick is to try "git remote -v". The problem is, whenever I try that, I get the same error as above. It seems no matter what I type after "git remote" will result in that error.

What am I doing wrong here?! I was cruising along so well until I hit this brick wall.

bjork24
  • 3,153
  • 7
  • 35
  • 46

5 Answers5

32

You need to actually create the git repo. Simply calling 'heroku create' won't set one up for you. For an existing folder, you want enter it and run something like:

git init
git add .
git commit -m 'Initial commit'

...and then you add the remote (fill in your heroku git repo name from heroku info here):

git remote add heroku git@heroku.com:sushi.git

If you're starting a fresh app and a git repo already exists in the current dir, heroku create will add the git remote for you, and you don't need to run that last command.

mkdir new-app
cd new-app
git init
heroku create

After that, create your app from that dir rails new . and run the git add and commit steps from above. Modify your app as desired, update git again with any changes, then git push heroku master to deploy.

Run more .git/config from the app's root dir to see the config file with all of your app specific git settings. This will list your remote repos.

Joost Schuur
  • 4,417
  • 2
  • 24
  • 39
  • 1
    DONT DO THIS!! IT ADDS THE ENTIRE Documents directory to the git repo – Uri Abramson May 30 '13 at 14:10
  • Uri, Could you explain please? – Dsel Jul 26 '13 at 18:56
  • 7
    I believe Uri forgot to 'cd' to his repo's directory and accidentally added and committed his "my documents" folder to his repo. – MetaFight Nov 24 '13 at 19:39
  • While using the git commit statement use double quotes `"` instead of single quotes `'` if you're providing a message that has spaces. If you execute the above `git commit` statement as it is, you'd get the command line blurting out error saying `git commit error:pathspect 'commit'' did not match any file(s) known to git.`. – ikartik90 Oct 25 '15 at 12:02
  • I had to use https instead of ssh (eg, https://git.heroku.com/my-app.git) for the fourth line of code. ssh gave me a fatal access rights error. – ericksonla Mar 28 '17 at 18:41
6

Ha! Just found out that you actually need to have a git repo created before the

heroku apps:create app_name

call. Simply do

git init
git add .
git commit -m "Initial Commit."

and then do the app creation command.

Hope this helps.

milosmns
  • 3,595
  • 4
  • 36
  • 48
0

I had a similar problem. The book is correct, but make sure you cd to the app directory first.

For example:

$ cd ~/rails_projects/first_app
David Cain
  • 16,484
  • 14
  • 65
  • 75
rcoswe
  • 11
0

Just make sure you are calling the commands in the right folder, check and verify path in command line to make you are where you initialized git. That was my problem.

Isaac Sekamatte
  • 5,500
  • 1
  • 34
  • 40
0

Heroku has updated their integration of git. official documentation here https://devcenter.heroku.com/articles/git

what you need to do is run heroku git:remote -a $heroku_app_name get heroku app name from heroku info

cheng yang
  • 1,692
  • 3
  • 12
  • 21