Progress:
TIER 2 · MODULE 08· Intermediate

git reflog

Your safety net. Almost everything you 'lost' is in here.

🎯 What & why

git reflog records every move of every ref tip — commits, resets, rebases, checkouts, the works. It's your local, private, time-travel log and the single most important recovery tool in Git.

🧠 Mental model

Branches are pointers. The reflog is the history of where each pointer has been. Even a reset --hard to oblivion leaves a breadcrumb here for ~90 days.

🛠️ Synopsis

git reflog [show] [<options>] [<ref>]
git reflog expire [--expire=<time>] [--expire-unreachable=<time>]
                  [--rewrite] [--updateref] [--stale-fix] [--all|<refs>...]
git reflog delete <ref>@{<specifier>}...
git reflog exists <ref>

🎚️ Switches & options

FlagWhat it does
--allOperate on reflogs of every ref, not just HEAD.
--expire=<time>Drop entries older than <time> (default 90 days, gc.reflogExpire).
--expire-unreachable=<time>Drop unreachable entries older than <time> (default 30 days).
-n <num>Limit show output.
--date=<format>Format timestamps: relative, iso, short, ...
git reflog expire --expire=now --all⚠️ Wipes your safety net. Combined with gc --prune=now, recovery is over.

📦 Subcommands

show — Print reflog entries (default subcommand).
git reflog show master
expire — Trim old/unreachable reflog entries. gc runs this for you.
git reflog expire --expire=30.days --all
delete — Drop a specific reflog entry by <ref>@{n} selector.
git reflog delete HEAD@{2}
exists — Exit 0 if a reflog exists for <ref>. Useful in scripts.
git reflog exists refs/heads/topic

💡 Use cases

🧪 Examples

The classic undo
git reflog
git reset --hard HEAD@{1}
Recover a deleted branch
git reflog --all | grep my-branch
git branch my-branch <sha-from-reflog>
Show with timestamps
git reflog --date=iso
Make sure HEAD's reflog is enabled (it is, by default)
git config core.logAllRefUpdates true

🎓 Recommendations

🪤 Common pitfalls

🔗 Related modules

📝 Quiz

Hit each option, then Check answers. Score is recorded; Next is always open.