Alan R. Soares
Alan R. Soares

Reputation: 1794

Git reference conflicts between branches (unable to update local branch)

I'm experiencing the following error while trying to git fetch a remote branch:

error: Ref refs/origin/remotes/my-branch is at some-hash but expected another-hash From github.com:my-repository ! some-hash my-branch -> origin/my-branch (unable to update local ref)

I have no idea what the hell just blew up. Any enlightenment?

Upvotes: 20

Views: 23894

Answers (4)

VonC
VonC

Reputation: 1326994

You also get that error message with "git fetch <group>"(man), when "<group>" of remotes lists the same remote twice, unnecessarily failed when parallel fetching was enabled.

That has been corrected with Git 2.40 (Q1 2023).

See commit 06a668c (19 Jan 2023) by Calvin Wan (CalvinWan0101).
(Merged by Junio C Hamano -- gitster -- in commit d26e26a, 27 Jan 2023)

fetch: fix duplicate remote parallel fetch bug

Signed-off-by: Calvin Wan

Fetching in parallel from a remote group with a duplicated remote results in the following:

error: cannot lock ref '<ref>': is at <oid> but expected <oid>  

This doesn't happen in serial since fetching from the same remote that has already been fetched from is a noop.

Therefore, remove any duplicated remotes after remote groups are parsed.

Upvotes: 0

Felipe Centeno
Felipe Centeno

Reputation: 3747

In my case it wasn't the branch name per se. I had a situation like this: this branch name dev/a_random_branch_name was conflicting with Dev/completely_different_branch_name. I was so confused that both the branches were not even close that I didn't notice at first that the folder name was mismatched.

To fix it I did the following:

  1. remove all contents of .git\refs\remotes\origin\dev
  2. create a new branch that matched the folder name casing already in source control: Dev/a_random_branch_name

Upvotes: 2

Alan R. Soares
Alan R. Soares

Reputation: 1794

I've found this error's cause:

Someone has created another branch with the same name, but different case.

What happened?

Git for windows isn't case sensitive. So, things just got crazy! Git couldn't distinguish one from another, mistaking the hash of each's head.

Solution:

Just cut the evil by its root. Wrong remote branch was deleted and evererything is nice as ever.

Upvotes: 29

JaredBroad
JaredBroad

Reputation: 680

For other googlers who get here: this is also another less drastic approach:

Navigate to .git\refs\remotes\origin directory - delete the master file,

Then do another git pull and it synchronizes successfully.

Upvotes: 26

Related Questions