Fatal error "not a git repository" Git

July 7, 2014 22.2k views


I've been trying to setup git. I've followed this tutorials step by step like 12 times.

But I get stuck in the same step: "git push origin master"
I get the following error:

fatal: '/testing.git' does not appear to be a git repository
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

Previously I've done:

git remote add origin ssh://gitadmin@xxx.xxx.xxx.xxx/testing.git
git remote -v

I've also tried with the complete path
git remote set-url origin ssh://gitadmin@xxx.xxx.xxx.xxx/home/gitadmin/git/testing.git

Without errors, but always the same error...
gitadmin is a user of my server, which is a debian 7 x32

Thanks in advance.

1 Answer

The tutorials you linked to just get you setup to use the git client. They don't set up the server side. Check out this tutorial:

How To Set Up a Private Git Server on a VPS

Have you created the empty repository on the server you are pushing to already? On the server run:

git init --bare path/to/testing.git
by Brian Rogers
This tutorial will show you how to set up a fully fledged Git server using SSH keys for authentication.
  • Although they're not in the tutorials I linked, I've done what's in the one you did (added the ssh key, ...)

    I've also created the empty repository the following way:

    git init

    While being in the testing directory, then I did:

    git add .

    And then a simple commit of an empty file, the comes the error.

    Thanks for the answer

  • In order for the server side repository to accept a push, it needs to be created with --bare flag.

    In order to initially set up any Git server, you have to export an existing repository into a new bare repository — a repository that doesn’t contain a working directory. This is generally straightforward to do. In order to clone your repository to create a new bare repository, you run the clone command with the --bare option. By convention, bare repository directories end in .git

    See here.

  • Thanks again, well now there is no error. But the output isn't the same, while in the tutorial shows this:

    user@host ~/git/testing $ git push origin master
    Counting objects: 4, done.
    Delta compression using up to 2 threads.
    Compressing objects: 100% (2/2), done.
    Writing objects: 100% (3/3), 266 bytes, done.
    Total 3 (delta 1), reused 1 (delta 0)
    To ssh://git@git.domain.tld/repository.git
       0e78fdf..e6a8ddc  master -> master

    in my case is just:

    everything up-to-date

    NOTE: I'm doing inside my-project.git

    git init && git remote add origin git@git.droplet.com:my-project.git
  • I've solved it, Thanks!! It was a misunderstanding between server side and client side.

Have another answer? Share your knowledge.