59

while pulling into my git repository from our central server, this error occured:

$ git pull origin master

From http://aaa/repo
 * branch            master     -> FETCH_HEAD
error: unable to resolve reference ORIG_HEAD: No such file or directory
fatal: Cannot lock the ref 'ORIG_HEAD'.

I've tried git gc (with --prune=now) and looking for a similar error, unfortunately with no luck.

vvondra
  • 3,022
  • 1
  • 21
  • 34
  • perhaps you might consider marking Brian's question as the correct answer, seeing as it has many more votes? – Simon East Jul 17 '15 at 03:11

6 Answers6

173

I had this problem, and I solved it by removing the file .git/ORIG_HEAD then doing the pull again. The .git/ORIG_HEAD file was 0 bytes instead of the git reference it was supposed to contain, so I just got rid of it.

Brian Minton
  • 3,377
  • 3
  • 35
  • 41
10

Check the git remote prune origin mentioned in addition of the git gc --prune=now in "git pull fails “unalble to resolve reference” “unable to update local ref”".

If you have a .git/rebase-merge, consider removing it (as in "git rebase and deleted rebasing branches causing “Interactive rebase already started” error message")

Check also the content of .git/HEAD, as in this issue.

If this is a repo corruption of some kind (see "Git corrupt master branch"), try first to clone your repo again, and re-apply your current modifications on top of that repo (through git format-patch if you need to)

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • 1
    Thanks, unfortunately none of the mentioned fixes worked, so I had to re-clone and apply the patch. – vvondra May 20 '12 at 09:22
9

This answer doesn't solve the OP's problem, but solves a similar one.

I had a similar problem (I got error: cannot lock ref ... is at ... but expected ...), but it was because there were two branches in the repo with the same name, but with different case. Maybe this answer could help people that get here, I wasn't able to find an answer elsewhere. I deleted one of the branches, and then deleted its corresponding reference from: .git/ref/.../branch_name, then git pulled. This happens due to me working on a case-insensitive file system, while the two branches were pushed on a case-sensitive file system.

For example, the two branches are BRANCH1 and branch1, and they are both under origin remote. First, delete one of the branches, for example BRANCH1. Then remove its ref:

rm .git/refs/remotes/origin/BRANCH1

Then git pull, and it should be fine.

Ariel Cabib
  • 2,042
  • 22
  • 14
6

I had to remove .git/ORIG_HEAD.lock, not (just) .git/ORIG_HEAD.

Gallaecio
  • 3,620
  • 2
  • 25
  • 64
3

This file is created when you git pull in a repository in order to not git pull in the same repository more then ones at the time and it gets deleted when the process is finished. If the process dies or become a zombie, then the file is not removed and you have to check manually if the git process still exists. If the process doesn't exists, then you have to delete the file and try to git pull again.

Romulus
  • 1,150
  • 3
  • 16
  • 26
0

I had Unix permission issues, I used the same git repo with two different users (one was root, the other was my private user).

So, I had to change the file ownership on .git/ORIG_HEAD to my personal user, that resolved the issue.

chown myuser:mygrp .git/ORIG_HEAD
gaborsch
  • 15,408
  • 6
  • 37
  • 48