Skip to content

Deleted accidentally?

Hasnat Anjum Haz edited this page Nov 8, 2021 · 1 revision

I have written a bunch of code yesterday in a git branch. Today instead of checking in to the branch, I deleted it accidentally! And only then I remembered, I haven't pushed the code to the remote too. Ah, it happens, so here comes git reflog

git reflog --no-abbrev

(Did you know they store so many information there?)

Copy the SHA1 for the commit at the tip of your deleted branch. Then

git checkout <SHA1>
git checkout -b <new-branch-name>

Tada! You have restored your deleted branch.

Clone this wiki locally