Git: Receiving "fatal: Not a git repository" when attempting to remote add a Git repo

I am introducing myself to Git by following this tutorial:

  • getting jekyll running on nearlyfreespeech.net

Everything works fine up until the part where the repo is added to my local machine:

git remote add nfsn ssh://USERNAME@NFSNSERVER/home/private/git/REPONAME.git

(After replacing USERNAME, NFSNSERVER, and REPONAME with the correct names) I receive the following error:

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

Can you help me get past this step?


Did you init a local Git repository, into which this remote is supposed to be added?

Does your local directory have a .git folder?

Try git init.


You'll get this error if you try to use a Git command when your current working directory is not within a Git repository. That is because, by default, Git will look for a .git repository directory (inside of the project root?), as pointed out by my answer to "Git won't show log unless I am in the project directory":

According to the official Linux Kernel Git documentation, GIT_DIR is [an environment variable] set to look for a .git directory (in the current working directory?) by default:

If the GIT_DIR environment variable is set then it specifies a path to use instead of the default .git for the base of the repository.

You'll either need to cd into the repository/working copy, or you didn't initialize or clone a repository in the first place, in which case you need to initialize a repo in the directory where you want to place the repo:

git init

or clone a repository

git clone <remote-url>
cd <repository>

My problem was that for some hiccups with my OS any command on my local repository ended with "fatal: Not a git repository (or any of the parent directories): .git", with fsck command included.

The problem was empty HEAD file.

I was able to find actual branch name I've worked on in .git/refs/heads and then I did this:

echo 'ref: refs/heads/ML_#94_FILTER_TYPES_AND_SPECIAL_CHARS' > .git/HEAD

It worked.