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

Lets create repository to experiment with:

Graphically git repository will look like this:


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.


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


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

Programista, domowy kucharz i "amator amerykańskiej polityki". Zbieram informacje z całej sieci, po odrzuceniu chwastów i dodaniu swojej opinii publikuje na blogu.