Resolving Conflicts During Rebase
You'll learn how to handle and resolve conflicts that arise mid-rebase, and how to continue or abort the operation.
What Happens When Rebase Hits a Conflict
Unlike a standard merge, a rebase replays commits one at a time onto a new base. If Git can't automatically apply a commit (because the same lines were changed differently), it pauses the rebase and asks you to resolve the conflict manually. Think of it like following a recipe step-by-step: if one ingredient is missing, you must handle that before proceeding to the next step.
When this happens, Git leaves you in a special "rebasing" state. Your repository isn't broken—it's just waiting for your decision.
The Resolution Workflow
- Identify conflicts: Run
git statusto see which files have conflicts (marked as "both modified") - Open conflicting files: Look for conflict markers (
<<<<<<<,=======,>>>>>>>) showing both versions - Manually edit: Choose which changes to keep, or combine them, then remove the conflict markers
- Stage the resolved files: Use
git add <filename>to mark conflicts as resolved - Continue the rebase: Run
git rebase --continueto move to the next commit
Git will repeat this process for each conflicting commit in your rebase sequence.
When You Need to Bail Out
If the conflicts are overwhelming or you realize the rebase was a mistake, you can abort at any time:
git rebase --abort
This returns your branch to exactly where it was before you started the rebase—like hitting undo on the entire operation.
Why This Matters in Data Science
When rebasing feature branches with analysis code or pipeline changes, conflicts in notebooks, scripts, or configuration files are common. Understanding the pause-resolve-continue cycle keeps your Git history clean without losing work.
Key Takeaway: During a rebase, conflicts pause the operation; resolve them file-by-file with git add and git rebase --continue, or use git rebase --abort to cancel the entire rebase safely.