AI Hints
Git & GitHub · Lesson 87 of 144

Rebase Conflicts

Continue, or abort.

⏱ 2 min read▶ Video at 1:34:49🎓 Free
Watch this lesson in the Git & GitHub courseWatch on YouTube ↗Full Git & GitHub course

A rebase replays commits one by one. If one of them changes the same line as main, the rebase pauses, and asks you to fix the conflict. The steps are almost the same as for a merge.

Rebase Conflicts
From the video: Rebase Conflicts
  • Commits are replayed one by one
  • A conflict pauses the rebase
  • Almost the same fix

A paused rebase

We rebase the intro branch onto main. Both changed the welcome line, so Git stops with a conflict. It tells us exactly what to do. Fix the conflict, add the file, then run git rebase dash dash continue.

git
git rebase main
Auto-merging index.html
CONFLICT (content): Merge conflict in index.html
error: could not apply d8cec74... Rewrite intro
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".
Could not apply d8cec74... Rewrite intro

Fix and continue

In our editor, we write the final line, and remove the markers. Then git add, and git rebase dash dash continue. Git may open your editor, to confirm the commit message. Just save, and close it. Git finishes replaying our commit. The log shows it now sits on top of main's friendlier welcome. And if it ever gets too confusing, git rebase dash dash abort puts everything back, exactly as it was before.

git
git add index.html
git rebase --continue
[detached HEAD 6d99d52] Rewrite intro
 1 file changed, 1 insertion(+), 1 deletion(-)
git log --oneline -n 3
6d99d52 (HEAD -> intro) Rewrite intro
5004186 (main) Friendlier welcome
f63a17a Link to about page

Summary

When a rebase pauses, fix the file, git add it, and git rebase dash dash continue. Or abort to go back. Next, the one rule of rebasing.

Key takeaways
  • Fix, then git add
  • git rebase --continue
  • git rebase --abort
Next up: The Golden Rule of Rebase — never rebase shared commits