Broken branch in git, fatal: your current branch appears to be broken

eirenaios picture eirenaios · Oct 8, 2015 · Viewed 14k times · Source

Here is my case:

  • I was working on one branch.
  • Pushed new commits to the remote.
  • Switched back to the master branch.

But suddenly after typing git checkout master command my computer encountered blue screen of death and an unexpected force shut down happened. After starting back my computer I have checked the status of my current branch and as a result I got each and every file as marked new files.

Now, I am stuck at this point and after git log command I am getting error

$ git log
fatal: your current branch appears to be broken

How to solve this problem and recover my branch?.

I am working with windows 7 and git bash latest version

Edit: I don't want to delete this branch.

Answer

David Zhang picture David Zhang · Jul 5, 2016

I meet similar issue on Windows 7. In my case,the current branch file (refer by ./git/HEAD) under \.git\refs\heads was broken.

I found the hash code of broken current branch on .git\logs\refs\heads with same branch name.

And I fixed the issue by opening that file (.git\logs\refs\heads\xxx) via notepad and copy the 4th number (the hash code) to (.git\refs\heads\xxx)