TIL: git reflog doesn't keep things forever
A coworker lost a branch. They knew they had done a hard reset a while back. They were certain reflog would save them. It didn’t — the entry had expired.
Git’s reflog has an expiry. Defaults:
- Reachable entries (things still part of some branch): 90 days.
- Unreachable entries (orphaned): 30 days.
git gc quietly prunes them on its schedule. Fine usually, not fine when you need to recover a month-old lost branch.
Changing it:
git config gc.reflogExpire "1 year"
git config gc.reflogExpireUnreachable "6 months"
Set globally (--global) if you want it on everywhere. For a specific repo you care about, set it per-repo.
Also useful: git gc honors these settings, so if you’ve already accidentally pruned, no amount of config change will bring things back. Act before you gc.
And: git fsck --lost-found can sometimes surface orphan commits that reflog missed, as long as they’re still in the object database. Combine with git show <sha> to see what’s in each.
Moral: reflog is a safety net, not an archive. For important work, push to a remote branch as well.