How to recover an accidentally deleted branch HEAD in git

Its quite pos­si­ble that you did a git reset –hard and moved your HEAD back to a com­mit only to real­ize that you switched back too far behind in your com­mit his­tory. Appar­ently every­thing is not lost. Git still pro­vides a way for you to recover from this dis­as­ter. Of course there is no way to go for­ward in git but what you can do is track the his­tory of your HEAD using the fol­low­ing command

git reflog

Now that you can see the com­mit SHA of where the head was just prior to your silly mis­take, you can do a git reset –hard to that com­mit to come back to that state. Once you get there, you can now take a deep breath of relief and then decide where you wanna go from there.


Ryan Sukale

Ryan is just a regular guy next door trying to manage his life and finances.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *