TortoiseGit Error - Could not get all refs. libgit2 returned: corrupted loose reference file

13,974

Your refs are stored inside the raw repository (in .git) in directories (named for each branch) under the "refs" directory. The problem is that one of these files has been corrupted. If you check the code here you'll see that the problem is either that the ref file is less than 40 bytes long, or has a 41st byte that is not a space (or tab, newline, etc). Search through the files in the .git/refs directory and you'll find the bad one. It should contain the 40-character hash of the commit which that branch refers to. You can safely fix it using Notepad.

Share:
13,974
John Mattucci
Author by

John Mattucci

Updated on July 20, 2022

Comments

  • John Mattucci
    John Mattucci almost 2 years

    I just got an error after a recent commit using Tortoise Git:

    "Could not get all refs. libgit2 returned: corrupted loose reference file"

    which pops up when I go to check the Log.

    Any ideas on how to rectify this?

  • Dean Wild
    Dean Wild over 9 years
    Worked for me. I was able to copy the remote ref file over the local corrupted one and taadaa!
  • Thirueswaran Rajagopalan
    Thirueswaran Rajagopalan over 7 years
    First of all, thank you cliffordheath ... I got this error popping up after doing a FETCH with PRUNE. After reading your answer. I browsed through the branch ref files in ..\.git\refs\remotes\origin. The HEAD file was being pointed to master branch as ref: refs/remotes/origin/master. In our repository the master/main branch is not master its another branch ref: refs/remotes/origin/our-master... Vola. It worked.... Thanks again @cliffordheath ...
  • it3xl
    it3xl over 6 years
    After deletion of the master branch and changing the HEAD to anather branch on my remote Git-server repo by command git symbolic-ref HEAD refs/heads/<your-master-replacement-branch>. I got this error on local repos. Fixed by git remote set-head origin <your-master-replacement-branch> on any local repo. Or just do the git clone from scratch.
  • always-a-learner
    always-a-learner about 2 years
    Work for me also, .git/refs/heads/ inside this master file is look not good so update it with the same master file in refs and then done. issue solved.