---
title: "How do I undo a git rebase?"
description: "A rebase went wrong? Reset the branch to ORIG_HEAD or to its entry in the reflog to get back exactly where you were before, even after the rebase has finished."
url: https://www.danny.engineering/answer/git/how-do-i-undo-a-git-rebase
author: Danny
published: 2026-11-27T00:00:00.000Z
updated: 2026-11-27T18:57:00.000Z
tags: ["Git"]
---

# How do I undo a git rebase?

## The short answer


If the rebase is still in progress, run `git rebase --abort`. If it has already finished, reset the branch to where it was before the rebase. Straight afterwards, `ORIG_HEAD` points there; at any later time, the branch's reflog does.


```bash
git rebase --abort              # rebase still in progress
git reset --hard ORIG_HEAD      # rebase just finished
git reset --hard feature@{1}    # or: the branch's previous position from its reflog
```


## Why it happens


A rebase does not edit your existing commits. It creates new copies of them on top of another base and then moves your branch pointer to the last copy. The original commits are still in the repository; nothing points at them any more, so they disappear from `git log`.


Git keeps two records that let you find them again:

- `ORIG_HEAD`, which rebase, merge and reset set to the commit you were on before they moved your branch.
- The reflog, a local log of every position your branches and `HEAD` have been at, with entries kept for weeks by default.

Undoing a rebase is just pointing your branch back at the old commit.


## How to fix it


### Abort a rebase that is still running


If Git stopped for a conflict and you would rather not continue, abort. This puts the branch and working tree back to how they were before you ran `git rebase`.


```bash
git status                # says "interactive rebase in progress" or similar
git rebase --abort
```


### Reset to ORIG_HEAD straight after the rebase


If the rebase finished and the result is wrong, and you have not run another reset, merge or rebase since:


```bash
git log --oneline -5 ORIG_HEAD   # check it shows your old commits
git reset --hard ORIG_HEAD
```


### Use the branch reflog


The most reliable option, even days later, is the reflog of the branch itself. A completed rebase moves the branch once, so the entry just before it is the pre-rebase state:


```bash
git reflog show feature
# 9c1e2f0 feature@{0}: rebase (finish): refs/heads/feature onto 3a7b1d4
# 51d0a8e feature@{1}: commit: Add validation to sign-up form
# ...

git reset --hard feature@{1}
```


If you have done several things since, read further down the list and pick the commit you want by its hash. You can also look at the `HEAD` reflog with plain `git reflog` and find the line just before "rebase (start)".


### Keep a backup branch next time


Before a risky rebase, a throwaway branch costs nothing and makes undoing trivial:


```bash
git branch backup/feature-before-rebase
git rebase main
# if it goes wrong:
git reset --hard backup/feature-before-rebase
```


### If you already force-pushed the rebased branch


After resetting locally, push the restored history back up. Use `--force-with-lease` so you do not overwrite commits someone else pushed in the meantime:


```bash
git push --force-with-lease
```


## Common pitfalls

- Relying on `ORIG_HEAD` after running other commands. Any later reset, merge or rebase overwrites it.
- Forgetting that `git reset --hard` discards uncommitted changes. Run `git status` first and stash anything you want to keep.
- Using `HEAD@{1}` instead of the branch reflog. During a rebase `HEAD` moves many times, so `HEAD@{1}` is usually one of the intermediate steps, not your original branch.
- Waiting too long. Unreachable commits are eventually removed by garbage collection; by default reflog entries for them expire after about 30 days.
- Expecting the reflog on another machine or the remote. It is local to your clone.

## Related reading

- [Git documentation: git rebase](https://git-scm.com/docs/git-rebase)
- [Git documentation: git reflog](https://git-scm.com/docs/git-reflog)
