Recovering a Deleted Branch

In this episode, we'll try to recover a deleted branch.

Transcript
Recovering a Deleted Branch

In this episode, we’ll try to recover a deleted branch. Using the “Reflog” tool in Git, we have quite a good chance of undoing this.

Let’s look at an example scenario. Here, we have a “feature/login” branch that contains a valuable commit. Still, we decide to delete the branch - maybe because we were told that the feature isn’t necessary anymore.
But…. well… shortly after deleting it, we realize that we need it back!

Let’s use a Git tool called “Reflog” to see if we can save the day. In case this doesn’t show up in your sidebar, then make sure the Reflog is activated in Tower’s preferences.

Think of the Reflog as a journal that keeps track of every movement of the HEAD pointer - when you’re doing a checkout, commit, reset, cherry-pick…

And maybe you remember: we just performed a “checkout” because we had to move to the “master” branch before deleting the feature branch. So right at the top, we have this checkout we just performed. And in order to undo deleting that feature branch, we can simply return to the state before that action.

Now, all we have to do is right-click the state we want to return to and choose to create a new branch on that commit.