On this page
The core idea
Git rarely deletes commits immediately. When you reset a branch, rebase or delete a branch, the old commits still exist; they are simply no longer referenced by a branch name. The reflog records every position HEAD and your branches have pointed to in your local repository, usually for around 90 days by default. As long as the work was committed at some point, you can find it in the reflog and point a branch back at it. Uncommitted changes are a different story, which is why committing often is a safety habit.
A practical approach
Step 1
Stop and avoid running more destructive commands. Run git reflog to see recent positions of HEAD with descriptions such as 'reset: moving to HEAD~3' or 'rebase (start)'.
Step 2
Find the entry just before the mistake and inspect it with git show HEAD@{n} or git log HEAD@{n} to confirm it contains your work.
Step 3
Create a rescue branch at that point with git branch rescue HEAD@{n}. This is non-destructive and gives you a safe copy.
Step 4
Compare the rescue branch with your current branch, then reset or cherry-pick to restore what you need.
Step 5
For a deleted branch, search the reflog for its last commit, or use git log -g, and recreate the branch at that commit.
Worked example
While cleaning up a feature branch, a developer runs git reset --hard HEAD~3 intending to drop one commit, and three days of commits vanish from git log. git reflog shows the entry 'commit: Add payment webhook tests' just before the reset. Running git branch rescue HEAD@{1} brings all three commits back on a new branch, and an interactive rebase on that branch removes only the one unwanted commit.
A mistake to avoid
Do not rely on the reflog for work that was never committed. git reset --hard and git checkout -- on modified files discard uncommitted changes permanently. Commit or stash before experimenting with history.
Try it yourself
In a practice repository, make three commits, run git reset --hard HEAD~2, then use the reflog to recover both commits on a new branch. Repeat with a deleted branch.
Your implementation checklist
- I commit or stash before rewriting history
- I can read reflog entries and find the state before a mistake
- I create a rescue branch before attempting a fix
- I can recover a deleted branch from its last commit
- I know the reflog is local and does not protect uncommitted changes
Share or cite this guide
Innovate with Ajay Editorial (2026-10-07). Recover Lost Work in Git with Reflog Before You Panic. https://innovatewithajay.com/blogs/recover-lost-work-with-git-reflog
