5

I realize that this question has been asked several times already, but unfortunately none of the solutions under the older questions have been able to solve my issue. Essentially, I'm trying to pull from a remote repository and I'm getting an error each time saying:

error: cannot lock ref 'refs/remotes/origin/photonic_link': unable to resolve reference 'refs/remotes/origin/photonic_link': reference broken
From https://gitlab.com/GXC_Dev/genxcomm-python-library
 ! [new branch]      photonic_link -> origin/photonic_link  (unable to update local ref)

Now if it matters as far as solving the issue, I had to switch my branch from master to photonic_link a week ago because I pulled the wrong branch (master) without realizing I was supposed to be working on a different one. This is also the first time I've tried to pull from the repository since I switched branches.

As I mentioned earlier, I've tried the solutions in the other answers and none of them have worked for me. I've tried git gc --prune=now and git gc, but I got the following response for both of those commands:

error: bad ref for .git/logs/HEAD
error: bad ref for .git/logs/refs/heads/photonic_link
error: bad ref for .git/logs/refs/remotes/origin/photonic_link
fatal: bad object refs/heads/photonic_link
fatal: failed to run repack

Then I tried git rm -rf .git/logs/refs/remotes/origin/photonic_link, and I received a fatal error:

fatal: pathspec '.git/logs/refs/remotes/origin/photonic_link' did not match any files

git rm -rf .git/refs/remotes/origin/photonic_link returns a "did not match any files" error similar to the one above as well.

Running git fetch returns the following:

remote: Enumerating objects: 215, done.
remote: Counting objects: 100% (215/215), done.
remote: Compressing objects: 100% (136/136), done.
remote: Total 215 (delta 119), reused 144 (delta 75)
Receiving objects: 100% (215/215), 69.08 KiB | 115.00 KiB/s, done.
Resolving deltas: 100% (119/119), completed with 8 local objects.
From https://gitlab.com/GXC_Dev/genxcomm-python-library
   98878cb..cef33e7  RF_Link_Modeling -> origin/RF_Link_Modeling
   256b31e..9b09944  bell_dev         -> origin/bell_dev
   9c5603e..6209abc  master           -> origin/master
error: cannot lock ref 'refs/remotes/origin/photonic_link': unable to resolve reference 'refs/remotes/origin/photonic_link': reference broken
 ! [new branch]      photonic_link    -> origin/photonic_link  (unable to update local ref)

The last thing I tried was going in and manually deleting line containing photonic_link from my .git/packed-refs file, but it doesn't exist in there. Does anyone know how I can resolve this issue?

4
  • If you are willing to lose some of your changes, you can just do git reset --hard <commit_id>. After doing that first time you push to remote you need to use git push -f origin <branch> Commented May 10, 2019 at 20:43
  • 1
    Does .git/refs/heads/photonic_link exist? If so, what type of file or directory is it, and what permissions does it have? If it is a file, does it contain a valid SHA-1?
    – torek
    Commented May 10, 2019 at 20:46
  • @congaoguier, I tried that and it gave me the same error as trying to push. @torek .git/refs/heads/photonic_link does exist as a file, it has all permissions for SYSTEM except special permissions, and it's empty as far as I can tell. Commented May 10, 2019 at 21:02
  • 1
    OK, an empty file would be invalid, but it's not clear how that happened. You can put a valid commit hash into it (assuming you know one) to fix that problem. Then the next problem is whether .git/refs/remotes/origin/photonic_link exists, and if so, what's wrong with it.
    – torek
    Commented May 10, 2019 at 21:31

2 Answers 2

10

This has happened to me because of the VM I was developing in crashed and left its filesystem in some inconsistent state.

What helped me:

  1. Check what went wrong with git for-each-ref. This will list the broken references, they look like warning: ignoring broken ref refs/remotes/origin/HEAD.
  2. Delete the Git directory where the remote references are kept: rm -rf .git/refs/remotes/origin. It is less dangerous than it looks because you delete only locally and still have your remote repository intact.
  3. Tell Git to match the local and remote branches again: git branch --set-upstream-to=origin/master master
  4. Now git pull should work.
1

What worked for me is

git fsck

then I copied all the broken referenced, missing references, hash 1 mismatch problem etc on the notepad++ like below

error: bad ref for .git/logs/refs/remotes/origin/Feature/PENTEST-Chnages
error: bad ref for .git/logs/refs/remotes/origin/Feature/MOTS-2382-SharingPortal
error: bad ref for .git/logs/refs/remotes/origin/Feature/MOTS-2764-kiosk-api-changes

then I modify them as below:

rm .git/logs/refs/remotes/origin/Feature/PENTEST-Chnages
rm .git/logs/refs/remotes/origin/Feature/MOTS-2382-SharingPortal
rm .git/logs/refs/remotes/origin/Feature/MOTS-2764-kiosk-api-changes

run it on git terminal, this fixes all my references.

Do a pull and it worked.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.