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:
git rebase mainGit:
- takes the first commit of your branch
- tries to apply it on top of
main - if it fails, it stops on that commit
- waits for you to resolve the conflict
What a conflict looks like
The file looks the same as during a merge:
<<<<<<< HEAD
console.log("from main");
=======
console.log("from feature commit");
>>>>>>> commit_hashThe 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
- Open the conflicting files
- Fix the code
- Remove the conflict markers
- Add the files:
git add file.js- Continue the rebase:
git rebase --continueIf you need to cancel:
git rebase --abortKey difference from a merge conflict
| Merge | Rebase |
|---|---|
| The conflict is resolved once | Conflicts can occur on every commit |
Resolution -> one git commit | Resolution -> git rebase --continue |
| The whole branch at once | Commits 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 rebaseoccurs 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 readyA concise answer to help you respond confidently on this topic during an interview.