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:
git push
from my work-PC, as I usually do, to the origin hosted at Bitbucket;git fetch
when I got home. There were no errors or warnings;git push
after working at home. There were no errors or warnings;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.
Following @bernard-paulus's comment, you can try
git gc --prune=now
which worked for me
You can also try
git for-each-ref
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With