33

I got the following when I try to git push to heroku

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

I try to follow ruby on rail tutorial book.

I think I installed the client heroku package(by downloading from heroku website and follow their instruction to install, GUI format installation). So my client side heroku should be ok (I am new to programming , so not sure if saying by this term is correct or not).

Then I open a new terminal and key in

git push heroku master

I got

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

Can anyone good at this explain which part I missed? i.e. have to move to some directory first?

Please show me the command since I might still have no idea without command.

PS: I think I have repository in my github already.

james.garriss
  • 12,959
  • 7
  • 83
  • 96
Simon Yu
  • 339
  • 1
  • 3
  • 3
  • 2
    possible duplicate of [Receiving "fatal: Not a git repository" when attempting to remote add a git repo](http://stackoverflow.com/questions/4630704/receiving-fatal-not-a-git-repository-when-attempting-to-remote-add-a-git-repo) – Andrew Marshall Dec 06 '13 at 00:51
  • 1
    Not a duplicate of it. – Jonathan Allard Apr 26 '14 at 21:35
  • Hello; I get the same error trying to acquire DebugKit for CakePHP. I'd like to amplify the question by asking WHY do I need to be IN a repository when, as I understand the instructions, I am attempting to DOWNLOAD FROM a repository? In other words, all I want is the content so I can use it. But ... if it is NECESSARY to create a repository in order to acquire the contents, WHY DON'T THE INSTRUCTIONS SAY THIS? Not all of us are familiar with "git" you know! – UncaAlby Nov 03 '14 at 23:18
  • UncaAlby you want `git clone ` but before the comment stack overlords see this, you may want to make this a question somewhere else. People will answer it.I'm sure there is an easy git workflow for beginners question somewhere. – pjammer Nov 05 '14 at 12:06

9 Answers9

16

You aren't on a git repository directory.

Yype pwd and make sure it's where you think you should be. Chances are you are in ~/ or something just before the directory you think you are in. Or maybe you are in C:/ drive instead of the one you are. To change your directory from drive c to d use this command cd D:/ then figure out your files with this command ls.

7_R3X
  • 3,904
  • 4
  • 25
  • 43
pjammer
  • 9,489
  • 5
  • 46
  • 56
  • 1
    Either that, or the original poster never initialized a repository in the first place. –  May 27 '14 at 04:24
14

Have you created a git repository? Create it using git init and then commit some files.

http://git-scm.com/book/en/Git-Basics-Getting-a-Git-Repository

Fiona T
  • 1,921
  • 1
  • 15
  • 18
5

update sep 2020

first, you have git repo required to create a heroku app

git init
git add .
git commit -m "initial commit"
heroku create
git push heroku master

how your code uploading to Heroku

Mr Coder
  • 507
  • 3
  • 13
3

Make sure you have followed all the steps in the Installation and setup section of the Rails Tutorial book.

The error message you are getting is indicating that you have missed the git init step.

Prakash Murthy
  • 12,923
  • 3
  • 46
  • 74
1

It is possible to encounter this error despite being within a git repository.

The answer at https://stackoverflow.com/a/60114649/3753318 has it exactly right:

In my case a system crash had caused the HEAD file to become corrupted. This guide shows how to fix that and other problems you may encounter.

https://git.seveas.net/repairing-and-recovering-broken-git-repositories.html

If the .git/HEAD file is messed up in some way, this will also lead to the "not a git repository error"

MarkR
  • 166
  • 1
  • 8
0

This error comes because you are trying to push the changes from a non-cloned working copy of your git repository. have you initialized git repo on the dir that you are working?? if not so initialize git repo by using git init and then either do a git clone or add a remote by using git remote add origin git@github.com:repourl.git for more detail refer this

Mani
  • 5,401
  • 1
  • 30
  • 51
0

This can happen if you mean to do git clone but instead do git checkout.

James Ward
  • 29,283
  • 9
  • 49
  • 85
0

If you previously had an initial commit from local to GitHub remote, or if you previously pulled from remote to local, then you have set up your remote. What worked for me is signing into my remote GitHub repo, and then this error went away and able to push/pull changes from local to remote, and vice versa.

Carlo Carandang
  • 187
  • 1
  • 8
0

This error will happen with gh, the Github CLI client, if you run a command like gh pr list outside of any Git repo. Instead, use a command that doesn't need to be run in a particular repo, like gh search prs.

Noumenon
  • 5,099
  • 4
  • 53
  • 73