How to fix a conflict during git rebase
Tested: we reproduced this error and confirmed the fix on Ubuntu 24.04 with Git 2.43.0, November 29, 2026.
When a rebase hits a conflict it pauses on that one commit. Fix the file, stage it and carry on:
# edit the file and remove the <<<<<<< ======= >>>>>>> markers
git add <file>
git rebase --continue
To cancel the rebase and get your branch back exactly as it was:
git rebase --abort
We reproduced the conflict, the --ours and --theirs swap, --abort and a replayed resolution with rerere on Git 2.43.
What Git prints
Rebasing a branch whose commit added a line where main had also added lines gave:
Rebasing (1/1)
Auto-merging f
CONFLICT (content): Merge conflict in f
error: could not apply 87eb5bc... x
hint: Resolve all conflicts manually, mark them as resolved with
hint: "git add/rm <conflicted_files>", then run "git rebase --continue".
hint: You can instead skip this commit: run "git rebase --skip".
hint: To abort and get back to the state before "git rebase", run "git rebase --abort".
git status confirms you’re mid-rebase and shows which commit stopped:
interactive rebase in progress; onto f7262c0
Last command done (1 command done):
pick 87eb5bc x
You are currently rebasing branch 'x' on 'f7262c0'.
Your three options
| Command | What it does | Use it when |
|---|---|---|
git rebase --continue |
Commits your resolution and moves to the next commit | You fixed and staged the files |
git rebase --skip |
Drops this commit from your branch entirely | The commit is no longer needed (its change is already upstream) |
git rebase --abort |
Ends the rebase and restores the branch as it was | You want to stop and think, or switch to a merge |
--skip throws the commit’s changes away, so only use it when you mean that. In our test, --abort returned the branch with nothing to commit, working tree clean.
Ours and theirs are swapped during a rebase
This trips most people up. A rebase checks out the branch you’re rebasing onto and replays your commits on top. So in the conflict markers:
<<<<<<< HEADis the upstream branch (for examplemain), plus any of your commits already replayed.>>>>>>> 87eb5bc (x)is your own commit being applied.
The same applies to the shortcuts. In our test, git checkout --ours f gave us main’s version of the file, not our branch’s. To keep your own commit’s version of a file during a rebase, use git checkout --theirs <file>. If you pick the wrong one, git checkout -m <file> brings the markers back.
Reading the markers
a
b
<<<<<<< HEAD
m
r2
=======
x
>>>>>>> 87eb5bc (x)
Keep the lines you want (here, all three), delete the marker lines, git add f and continue. For help choosing between two edits, set git config --global merge.conflictStyle zdiff3 so Git shows the original lines too. The merge conflict guide covers markers, conflict types and checking for leftover markers in detail. They behave the same way in a rebase.
Stop resolving the same conflict twice
rerere (“reuse recorded resolution”) remembers how you fixed a conflict and applies it the next time the same conflict appears:
git config --global rerere.enabled true
With it on, Git printed Recorded preimage for 'f' the first time. After we resolved, reset and ran the same rebase again, it printed Resolved 'f' using previous resolution. and the file already held our fix. You still git add and git rebase --continue yourself, so you can check its work. The Pro Git chapter on rerere explains the details.
If you finished the rebase and regret it
The old commits are still in the reflog:
git reflog
git reset --hard <hash-before-the-rebase>
Straight after a rebase, ORIG_HEAD usually points at the branch tip from before it, so git reset --hard ORIG_HEAD often works. Check git log ORIG_HEAD first, because other commands also move ORIG_HEAD. reset --hard discards uncommitted changes, so commit or stash anything you want to keep.
Pushing after a rebase
If the branch was pushed before the rebase, a normal push is rejected because the history changed. Use:
git push --force-with-lease
It refuses if someone else pushed to the branch in the meantime. If your push is rejected without a rebase involved, see push rejected (non-fast-forward).
FAQ
How do I fix a rebase conflict in Git?
Edit each conflicted file to the version you want and remove the markers, run git add on it, then git rebase --continue. Repeat if the next commit conflicts too. git rebase --abort cancels the whole rebase and puts your branch back exactly as it was.
Why does a rebase give me the same conflict more than once?
A rebase replays your commits one at a time. If several of your commits touch the same lines that changed upstream, each one can conflict in turn. Turning on rerere lets Git reuse a resolution it has seen before.
Is git rebase risky?
Not for your own local branch: git rebase --abort undoes it mid-way and git reflog finds the old commits afterwards. It's risky on a branch other people have pulled, because the rewritten commits replace theirs and you'll need a force push.
When should I avoid git rebase?
Avoid it on shared branches such as main, and on a branch that already has a pull request others are reviewing commit by commit. Use a merge there instead. Rebase is best for tidying your own branch before you share it.
