Skip to main content

What is a conflict during rebase?

A conflict during git rebase is a situation where Git cannot apply the next commit on top of the new base, because the changes conflict with the existing code.

Simply put: Git tries to "replay" your commits one by one, and at some step they do not match the current state of the branch.


When a conflict occurs during rebase

A conflict appears if:

  • you are rebasing onto a branch where the code has already changed significantly
  • your commit changes the same lines as commits in the new base

Unlike merge, the conflict does not occur for the whole branch at once, but on a specific commit.


What happens during rebase

When you run:

bash
git rebase main

Git:

  1. takes the first commit of your branch
  2. tries to apply it on top of main
  3. if it fails, it stops on that commit
  4. waits for you to resolve the conflict

What a conflict looks like

The file looks the same as during a merge:

text
<<<<<<< HEAD console.log("from main"); ======= console.log("from feature commit"); >>>>>>> commit_hash

The difference is in the context:

  • HEAD - the new base (main)
  • the lower part - the changes of the specific commit currently being applied

How to resolve a conflict during rebase

  1. Open the conflicting files
  2. Fix the code
  3. Remove the conflict markers
  4. Add the files:
bash
git add file.js
  1. Continue the rebase:
bash
git rebase --continue

If you need to cancel:

bash
git rebase --abort

Key difference from a merge conflict

MergeRebase
The conflict is resolved onceConflicts can occur on every commit
Resolution -> one git commitResolution -> git rebase --continue
The whole branch at onceCommits one at a time

Why rebase seems harder

  • there can be more conflicts
  • you need to understand which commit you are on
  • it is easy to get confused without experience

However:

  • each conflict is local and logical
  • the resulting history is cleaner

Interview phrasing

A conflict during git rebase occurs when Git cannot apply the next commit on top of the new base, and requires manually resolving the conflict and continuing the rebase.

Short Answer

Interview ready
Premium

A concise answer to help you respond confidently on this topic during an interview.