Theory
Theory: The Reflog is a Local Journal of Names
Every time a ref in this clone moves, Git can append a line to that ref’s log. It is not replicated. It is not a backup of other clones.
Invariants
HEADand each branch can have a reflog.- Default expire is on the order of 30 days (
gc.reflogExpire). HEAD@{1}is “where HEAD was last time,” not “parent commit.”- Recovering a deleted branch is
git switch -c name <hash-from-reflog>.
main moved C → D → E
reflog E HEAD@{0}
D HEAD@{1}
C HEAD@{2} (local only)
What can break
- Expecting a teammate’s reflog to contain your amended commit.
gc --prune=nowafter expire.
How to read this chapter
How it works, recover a branch, the 30-day window, step-by-step scenarios.