442

When I tried to push an existing repository on github.com, and it when I entered the command the website prompted me to put into the terminal, I got this error message fatal:

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

If anyone could help me with this, then that would be great, thanks.

Andrew Marshall
  • 95,083
  • 20
  • 220
  • 214
user3072482
  • 4,489
  • 3
  • 13
  • 5
  • 19
    Are you sure you are CD'd into a git repository directory or subdirectory in your terminal? – jraede Dec 06 '13 at 00:13
  • 1
    This can also happen if you exported your `CDPATH` environment variable, and one of the sub-directories of a repo happens to be named same as another non-repo-subdir under one of the paths in your `CDPATH`. Sounds crazy, but that wasted hours of my time recently before solving it. – MarkHu Jun 16 '17 at 00:09
  • similiar solution https://stackoverflow.com/questions/4630704/git-receiving-fatal-not-a-git-repository-when-attempting-to-remote-add-a-git – CuriousDev May 21 '21 at 07:24
  • You need to be in the directory that holds the repo, it typically has the '.gitignore' file. – Eddie Kumar Sep 14 '22 at 15:06
  • 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 Dec 03 '22 at 22:18

1 Answers1

803

The command has to be entered in the directory of the repository. The error is complaining that your current directory isn't a git repo

  1. Are you in the right directory? Does typing ls show the right files?
  2. Have you initialized the repository yet? Typed git init? (git-init documentation)

Either of those would cause your error.

ΩmegaMan
  • 29,542
  • 12
  • 100
  • 122
daniel gratzer
  • 52,833
  • 11
  • 94
  • 134