41

I'm trying to setup gitosis according to the instructions here.

It works fine from my remote machine so the server seems to be setup fine but I'd also like to be able to do development on my gitosis server machine from a different user account (not the git user created in the gitosis setup).

I've copied the key and modified the gitosis.conf so that the other user account has access but when I try to clone it seems to work except at the end it says:

git Warning: remote HEAD refers to nonexistent ref, unable to checkout

and I end up with an empty directory except for .git

I've google for this a bit but have no real insight into what the problem is

srboisvert
  • 12,679
  • 15
  • 63
  • 87
  • For those who ran into this problem with GitHub and took the first Hit on Google, see http://stackoverflow.com/questions/1485578/how-do-i-change-a-git-remote-head-to-point-to-something-besides-master and https://help.github.com/articles/error-remote-head-refers-to-nonexistent-ref-unable-to-checkout – Tino Jul 01 '12 at 13:21

7 Answers7

25

I found out what was going wrong. The problem was that I wasn't paying attention to the warnings when I was pushing to my gitosis server so I didn't realize that I wasn't pushing a particular branch. I had assumed it would just push the current but that isn't the case until you set:

git config push.default current
srboisvert
  • 12,679
  • 15
  • 63
  • 87
  • This is the post that tipped me off to it: http://stackoverflow.com/questions/1475468/git-push-failed-you-did-not-specify-any-refspecs-to-push and the fact that when I did git branch -r based on Michael Krelin's answer and got nothing back. – srboisvert Dec 25 '09 at 23:30
  • Thanks for this. I ran into same problem. – Dilawar Dec 14 '11 at 18:14
  • Thanks for this post. I guess the part I am not understanding is where you are when you are doing this. I get the head error as well but I am not sure where you doing the git config push.default current – Chris May 10 '13 at 15:05
22
  1. Do the git branch -r and git checkout -b master <remotebranchofinterest>

  2. Check the HEAD file in remote .git.

  3. Check if somebody already asked the question: here

Community
  • 1
  • 1
Michael Krelin - hacker
  • 138,757
  • 24
  • 193
  • 173
18

One more possible cause for this warning might be that the master branch in the repository is missing (OR) the repository does NOT use a master branch. If this is the case, just don't worry about the Warning!, use

git checkout <some_existing_branch>

The warning is because, by default, after the pull git tries to checkout into the master branch.

Boopathi Rajaa
  • 4,659
  • 2
  • 31
  • 53
  • 1
    This is a problem for me right now. If you're using pip to install Python packages from git, it seems git tries to checkout master first, then switches to whatever branch or commit you ask it to. The first step will fail if you don't have master in the repo. – tobych Jan 24 '13 at 22:02
2

Had a similar problem. It seems that on my first push I did git push origin master:/refs/heads/master instead of git push origin master:refs/heads/master (notice the extra slash). This caused my master to be placed (in the remote repository) at refs/heads/refs/heads/master instead of refs/heads/master. The fix was to reorganize the folders on remote and re-push.

Cristian Vrabie
  • 3,972
  • 5
  • 30
  • 49
1

Keep it simple. Add to gitosis authorization and SSH key for the user account on your server and clone as usual:

user@server$ git clone git@server:repo.git
Greg Bacon
  • 134,834
  • 32
  • 188
  • 245
  • That's exactly what I did and that resulted in the error message. Access appears to be fine based on the git output (I enabled debugging to give me more insight). – srboisvert Dec 25 '09 at 21:57
0

I use tortoiseGit and I'm not aware of how to use git via the command line. So I always wonder how I can avoid such problem in my tortoise. So maybe I am not alone. I fixed the problem this way:

  • clone the remote repo
  • right click on the root folder and from there choose an existing branch

Im my case, there was only a branch "dev", without master. So when I tried to clone there was no local branch to check out and as soon as I switched to "dev" it was able to check out all the content successfully. Hope that will be helpful.

carols10cents
  • 6,943
  • 7
  • 39
  • 56
0

If you are trying to clone over http:// note that you need a git newer than 1.6.6 - otherwise you should use a git:// based URI.

EvdB
  • 1,759
  • 2
  • 12
  • 19