giusti
giusti

Reputation: 3548

Git fetch gives "cannot lock ref" error message but seems to work anyway

Sometimes when I try and run git fetch I get the following response:

error: cannot lock ref 'refs/remotes/origin/branchname': is at XXXXXX but expected YYYYYY

The steps that I took that caused this were, to the best of my recollection, the following:

  1. I did a git push from my work-PC, as I usually do, to the origin hosted at Bitbucket;
  2. I did an uncommon git fetch when I got home. There were no errors or warnings;
  3. I did an uncommon git push after working at home. There were no errors or warnings;
  4. I did a git fetch when I arrived at the work today.

Step 4 caused the error message. My local repository had the offending branch checked out. Still I just ran git pull and it seemed to work.

This is not the first time I saw this error message. The first time it happened, I fetched another team's repository to update my local copy which had been sitting untouched (no fetching, no work, no pushing) for one month or two. When I pushed my changes, my co-worker got the error.

So in the two cases it seems to be somewhat related to local repositories which stay untouched for a while. But a sample of two is quite small to draw any conclusions.

I'd like to know what could be causing this. And, more importantly, if it is indeed harmless or if I'm at risk of losing work.

Upvotes: 11

Views: 14895

Answers (2)

ManojP
ManojP

Reputation: 6248

I have tried multiple options but below command worked for me. Putting it here for others if the above command does not work.

git pull -p

Upvotes: 2

David Norman
David Norman

Reputation: 19899

Following @bernard-paulus's comment, you can try

git gc --prune=now

which worked for me

You can also try

git for-each-ref 

Upvotes: 28

Related Questions