Cannot pull, git cannot resolve reference ORIG_HEAD

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.


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.


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)

Tags:

Git