If you ever completely break your code during a bad Git merge or accidentally delete a branch, DO NOT panic. Use git reflog.

Ever do a git reset --hard, mess up an interactive rebase, or accidentally delete a local branch containing days of your hard work? We've all been there, staring at the terminal with a sinking feeling in our stomach while frantically wondering if our IDE has local history backups. Before you accept defeat and start rewriting everything from scratch, you need to know about Git's built-in time machine.

Just type git reflog into your terminal.

Unlike the standard git log, which only shows your current branch's commit history, the reflog tracks absolutely every single action that changes the tip of your branches locally. It records everything, even commits that are now "orphaned" and no longer part of any active branch. You’ll get a list of all your recent actions with an index ID (like HEAD@{2}). Once you spot the state your repository was in right before you made your catastrophic mistake, just run git reset --hard HEAD@{2} and boom—your project is instantly restored. Save this command; it will absolutely save your sanity one day!

Posted Apr 2, 2026, 1:23 AM UTC

10
Loading comments…