Don't panic - How to recover from a git force push

2 min read Original article ↗

git push --force seems to have a reputation as one of the scarier Git commands.

I was reading a front page HN article yesterday and saw something which crops up reasonably often:

My first troubling discovery was in 2025, when I made several errors then did a push -f to GitHub and blew away the git history for a half decade old repo. No data was lost, but the log of changes was

But force pushing is usually not as catastrophic as people think. I do it occasionally by accident, and I don't think I've lost any history or data yet (touch wood!)

If you force pushed to GitHub, the overwritten commits aren't immediately deleted. You can recover them through the GitHub UI (details here) or programmatically via the GitHub API (details here). GitHub holds onto those commits for a while, so you usually have a comfortable window to fix things.

If you force pushed to your own machine, git reflog is your friend. The reflog tracks where your branch references have pointed, so you can find the pre-force-push commit and reset back to it (details here).

The takeaway: force pushing is worth being careful about, but it's rarely the end of the world. Know your recovery options and it becomes a lot less scary.


  • Credit to the Stack Overflow authors whose answers are linked to in this post: brandizzi, Pierrick Hymbert, and Ken.
  • I wrote this post by converting my real world experiences with Git into thoughts, and having them actualised into an initial set of ideas by Claude Opus 4.6 extended. I then heavily edited what Claude produced and hand pasted it into this Gist.