Skip to content

How to Fix Git Rebase Conflicts Step by Step

DodaTech 2 min read

In this tutorial, you'll learn about How to Fix Git Rebase Conflicts Step by Step. We cover key concepts, practical examples, and best practices.

The Problem

You run git rebase main and get:

CONFLICT (content): Merge conflict in src/app.js
error: could not apply abc1234... Add new feature
hint: Resolve all conflicts manually, mark them as resolved with "git add", and run "git rebase --continue".

Git is replaying your commits on top of the target branch, and one of your commits conflicts with changes on main. Unlike a merge conflict (resolved once), rebase conflicts can happen multiple times since each commit is replayed individually. If you have 5 commits being rebased, you may need to resolve conflicts 5 separate times.

Quick Fix

1. Check which files conflict

git status

Expected output:

rebase in progress; onto def5678
You are currently rebasing branch 'feature' on 'def5678'.
  (fix conflicts and then run "git rebase --continue")
  (use "git rebase --skip" to skip this patch)

both modified:   src/app.js

2. Open the conflicted file and resolve

<<<<<<< HEAD
const title = "Main Branch Title";
=======
const title = "Feature Branch Title";
>>>>>>> abc1234 (Add new feature)

Keep one version or combine both, then remove the conflict markers:

const title = "Feature Branch Title";

3. Mark the file as resolved

git add src/app.js

4. Continue the rebase

git rebase --continue

Git opens your editor to write a commit message. Save and exit to apply this commit and move to the next one.

5. Repeat for each conflicting commit

If multiple commits conflict, repeat steps 1–4 for each one. Run git status after each --continue to see the next commit being applied.

6. Abort the rebase if needed

git rebase --abort

This restores your branch to the state before git rebase was run. None of your commits are lost.

7. Skip a commit that's no longer needed

git rebase --skip

Use this when a commit's changes are already present in the target branch or if the feature is no longer relevant.

8. Use a merge tool for complex conflicts

git mergetool

Expected output:

Merging: src/app.js
Normal merge conflict for 'src/app.js'
{left}: modified file           (def5678... main)
{right}: modified file          (abc1234... Add new feature)

Configure VS Code as the merge tool:

git config merge.tool vscode
git config mergetool.vscode.cmd 'code --wait --merge "$REMOTE" "$LOCAL" "$BASE" "$MERGED"'

Prevention

  • Rebase frequently to avoid large, painful conflicts
  • Use git rebase --interactive to squash commits into fewer, cleaner patches
  • Communicate with teammates about which files you're editing
  • Pull the latest main before starting a feature branch
  • Use git merge instead of rebase for shared branches to avoid rewriting history
  • Review the commit list with git log --oneline main..HEAD before rebasing to understand what's being replayed

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro