1

I have often been getting this error (or similar ones) for months now when I fetch.

How do I fix this? What causes this? Here is what is happening, step by step.

After a fetch:

error: cannot lock ref 'refs/remotes/origin/master': is at 1b8080a7ad8afa75a919feabeae31a8846763b73 but expected 67f1a4d428b7ab46a0fa62b4bb0d920592f920d9
From https://github.com/payne911/UdeM
 ! 67f1a4d..1b8080a  master     -> origin/master  (unable to update local ref)

error

After clicking "Close" on first pop-up:

close

After clicking "Close" on the second pop up:

closing

Pressing "Pull origin":

error: Your local changes to the following files would be overwritten by merge:
    Trimestre_4/IFT3325_Teleinfo/devoirs/2/class_diag.png
Please commit your changes or stash them before you merge.
error: The following untracked working tree files would be overwritten by merge:
    Trimestre_4/IFT3913_Qual_Metr/TP/3/~$apport.docx
Please move or remove them before you merge.
Aborting

enter image description here

So now the files were actually pulled, but not fully? And despite apparently not having been pulled since I can still click the "pull" button, they now appear as if they were modifications that I had done on this computer and that I need to commit them? Strange!

I commit and press "Pull Origin":

error: unable to unlink old 'Trimestre_4/IFT3325_Teleinfo/devoirs/2/rapport_tp2.docx': Invalid argument

enter image description here

That file wasn't even in the committed files! Though it was indeed opened. I closed it and pressed the button again:

enter image description here

Notice that I've successfully committed the changes which weren't changes from my part. Now I have a 'merge commit' set up. Then pressing "Push" gives no error and I'm back to normal.

enter image description here

payne
  • 4,691
  • 8
  • 37
  • 85
  • have you checked [this similar issue](https://stackoverflow.com/questions/10068640/git-error-on-git-pull-unable-to-update-local-ref/27278221)? though it really depends on what stunt people do on that particular repository. force push is one thing you should avoid if possible.. – Bagus Tesa Nov 29 '18 at 01:16
  • It did not solve the problem. There are weirder things that started happening: after the fetch on my other computer, pressing `pull` actually pulls the files, but then it doesn't "complete" the whole process and so (I assume) aborts abruptly without deleting the files that were just imported. Thus, now I have all the newly pulled files appearing as needing to be committed on the left despite those files actually all coming from the `pull` which didn't actually finish. It then becomes impossible to pull properly because of merge conflicts. Very weird! – payne Nov 29 '18 at 05:38

1 Answers1

0

First, on Windows, make sure you don't have an active process which would keep an handle on one of the files managed by Git. That would explain the second part of your error messages.

Regarding the first one, check if desktop/desktop issue 4325 can help:

  • Open the repository in GitHub Desktop
  • Go to the file menu and select Repository > Open in Command Prompt
  • Run the command rm .git/refs/remotes/origin/master to delete the broken ref
  • Run the command git fetch origin to grab a new copy of the ref
  • Run the command git branch -u origin/master to have your local master branch track the origin/master branch

Check also if the issue persists when you (for testing) clone again the repo in a new local empty folder.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • `'rm' is not recognized as an internal or external command, operable program or batch file.` is the error I get on the 3rd step in the command prompt. – payne Nov 29 '18 at 06:06
  • @payne then use `del .git\...`. `rm` is available through Git For Windows path. – VonC Nov 29 '18 at 06:07
  • `del .git/refs/remotes/origin/master` gives me `Invalid switch - "refs".`. – payne Nov 29 '18 at 06:07
  • @payne use \, not / – VonC Nov 29 '18 at 06:08
  • All done! Should I execute those steps on my other computer too? – payne Nov 29 '18 at 06:09
  • @payne First check if the issue persists on your current computer. Then try on the other one. – VonC Nov 29 '18 at 06:10
  • I'm still experiencing the issue, though at least now it doesn't duplicate files/abort/ask-me-to-commit-duplicated-files. I'm only stuck with the reflock issue. See [this screenshot](https://i.snag.gy/fLIbAg.jpg). – payne Dec 04 '18 at 01:55
  • @payne Would https://stackoverflow.com/a/15458951/6309 help in that reflock case? – VonC Dec 04 '18 at 07:09
  • That seems to be exactly the same answer as yours. – payne Dec 05 '18 at 02:55