Daily Software Tips & Tricks

Bite-sized knowledge to improve your coding skills daily.

Saving Yourself with Git Reflog

May 29, 2026

We've all been there: you run a destructive command like `git reset --hard` or accidentally delete a branch, and panic sets in. Before you accept defeat, remember that Git rarely actually deletes anything immediately. It keeps a secret history of every single action you take locally in a tool called the reflog.

Just type `git reflog` in your terminal to see a list of your recent movements, even the ones you thought you lost. Once you find the commit hash from right before your mistake, you can run `git reset --hard <commit-hash>` to bring your code back from the dead. It's the ultimate undo button for Git.