Introduction
Git keeps several special "auxiliary" refs in .git/ to record state during multi-step operations. Knowing them turns scary recoveries into one-liners.
ORIG_HEAD
ORIG_HEAD is set whenever a "dangerous" operation moves HEAD by a lot: merge, rebase, reset, am. It captures the previous tip so you can undo:
git merge feature
# decide it was a mistake
git reset --hard ORIG_HEAD
Same trick after a bad rebase or reset: