git reflog records every movement of HEAD in your local repository — commits, resets, checkouts, rebases, and merges. This makes it the ultimate safety net for recovering from "I just destroyed my work" situations. Deleted branches, lost commits, and bad resets can almost always be recovered with reflog.
GitReflogRecoveryCLIgit reflog
HEAD@{N}), the action (commit, checkout, reset, etc.), and the commit message. This is where you look when something goes wrong.git reflog --date=iso
git reflog show feature-branch
# Find the commit before the bad reset
git reflog
# Reset back to it
git reset --hard HEAD@{3}
git reset --hard, reflog records the previous state. Find the entry just before the reset in the reflog output, then reset back to it. This is the most common recovery use case and saves developers daily.# Find the last commit of the deleted branch
git reflog
# Recreate the branch pointing to that commit
git branch recovered-branch HEAD@{5}
git checkout HEAD@{10}
git cherry-pick HEAD@{7}
git reflog show stash
git stash drop or git stash clear may still be visible here. You can recover dropped stashes by cherry-picking their SHA from this list.# Find the SHA of the dropped stash git reflog show stash # Apply it directly git stash apply SHA
git reflog immediately after an accidental reset or deletion.HEAD@{N} entry that represents the state you want to recover.git reset --hard HEAD@{N} to restore to that exact state.git branch new-branch HEAD@{N} to create a branch without losing current work.By default, reflog entries expire after 90 days (unreachable objects after 30 days). You can change this with git config gc.reflogExpire. Once an entry expires and Git garbage collects it, the data is permanently gone — so act quickly when recovering lost work.
No — reflog is strictly local. Remote repositories (like GitHub) do not keep reflog entries for your pushes. However, as long as you haven't run git gc locally and the expiry hasn't passed, your local reflog has everything you need to recover.
git log shows the commit history of a branch — only commits reachable from the current HEAD. git reflog shows every movement of HEAD including checkouts, resets, and rebases. Reflog can find commits that are no longer in any branch's history.