Git gotcha

A little Git gotcha that I’ve seen crop up from time to time is an obtuse error encountered when trying to pull a branch or carry out a Git fetch command:

  • error: cannot lock ref ‘refs/remotes/origin/feature/xyz’: is at aff0047acaf8f324f70b9d7f71279f9ed5efb66d but expected 4b3db3223c87a8b0a06ed0f731aa15b5d8f6dfc8
  • ! 4b3db3223..e7a86e61afeature/xyz -> origin/feature/xyz (unable to update local ref)

This can affect developers during their day to day workflow using Git but where its most commonly noticed is on the build server when all the CI builds start failing, emails get sent, alarms go off and people get shouty. 😉

It’s not particularly obvious, but this can occur if there are two branches on origin with the same name but different capitalisation e.g.

  • feature/xyz
  • feature/Xyz

This only occurs on Operating Systems with case insensitive file systems such as Windows.

To resolve the issue rename or delete one of the branches and you’re good to go again.

Leave a Reply

Your email address will not be published. Required fields are marked *