Undoing a git rebase
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
Undoing a rebase depends on whether the rebase is still in progress or has already finished. If it is still running, the safest answer is usually git rebase --abort. If it already completed, the usual recovery tool is the reflog, often combined with resetting back to the commit you had before the rebase started.
Case 1: Rebase Is Still In Progress
If Git is currently rebasing and you want to stop and return to the pre-rebase state, use:
This is the cleanest undo path because Git still has the rebase state available and knows how to restore the branch.
A quick check is:
If the output says a rebase is in progress, --abort is usually the right tool.
Case 2: Rebase Already Finished
Once the rebase has completed, --abort no longer applies. At that point, use the reflog to find the commit your branch pointed to before the rebase.
You will often see an entry that lets you identify the pre-rebase position. Then reset back to it.
The exact reflog entry number varies, so inspect the reflog before resetting.
ORIG_HEAD Is Often Helpful
Git often stores the previous branch tip in ORIG_HEAD, which can make recovery simpler.
This works only if ORIG_HEAD still points to the state you want. The reflog is more general because it gives you a visible history of reference movement.
What If You Already Pushed?
If the rebased history has been pushed, undoing it becomes a coordination problem as well as a Git problem. Resetting locally is easy. Replacing the remote history may require a force push.
Use --force-with-lease, not a blind force push, and only after checking whether other people may already be based on the rebased commits.
A Safe Recovery Workflow
A practical workflow is:
- inspect
git status - inspect
git reflog - identify the pre-rebase commit
- reset only after you are sure which state you want
- coordinate before rewriting a shared remote branch
That avoids making a history-rewrite mistake worse.
Why Reflog Matters So Much
The reflog records where branch references and HEAD have pointed recently. Even when the commit graph looks confusing after a rebase, the reflog often gives you a straightforward breadcrumb trail back to the previous tip.
That is why it is the first recovery tool to reach for once the rebase has already completed.
Common Pitfalls
Interactive Rebase Recovery
If the rebase was interactive and you dropped, reordered, or edited commits, the reflog is still the recovery map. You do not need to remember the exact sequence manually as long as the reflog entry before the rebase is still available.
The most common mistake is using git rebase --abort after the rebase has already finished. At that point, there is nothing to abort.
Another mistake is resetting to a guessed commit instead of inspecting the reflog carefully first.
Developers also often force-push rewritten history without checking whether teammates are already using the remote branch.
Summary
- Use
git rebase --abortonly while the rebase is still in progress. - Use
git reflogto recover once the rebase has already completed. - '
ORIG_HEADis often a convenient shortcut to the pre-rebase position.' - Be extra careful if the rebased history was already pushed.
- Inspect first, then rewrite history deliberately.

