• 0

How to recover an accidentally deleted branch HEAD in git

Its quite possible that you did a git reset –hard and moved your HEAD back to a commit only to realize that you switched back too far behind in your commit history. Apparently everything is not lost. Git still provides a way for you to recover from this disaster. Of course there is no way to go forward in git but what you can do is track the history of your HEAD using the following command

git reflog

Now that you can see the commit SHA of where the head was just prior to your silly mistake, you can do a git reset –hard to that commit 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.