skip to Main Content
I Have Removed Wrong Branch (with Force) By Mistake, What Now?

I have removed wrong branch (with force) by mistake, what now?

Lets create repository to experiment with:

Graphically git repository will look like this:

graph

We are currently on master branch. Let’s say we remove (by mistake) feature/Democratic branch with force (cause branch is not merged into master).

git branch -D feature/Democratic

To revert that change we need to find SHA1 of last commit made on that branch.

Where to look? If you use terminal look at branch deleting command.

delete_branch_command_result

And in this you can use short SHA1 fee449c to bring back deleted branch.

git checkout -b feature/Democratic fee449c

What to do when you have closed terminal or you use GUI to manage your repository?

We need to use time-machine for git

git reflog

git_reflog

from that you can deduce last commit from feature/Democratic branch

Back To Top