0
0
GitHow-ToBeginner · 3 min read

How to Continue Git Rebase After Conflict

When a conflict occurs during a git rebase, resolve the conflicting files manually, then run git add <file> to mark them as resolved. Finally, continue the rebase with git rebase --continue to proceed with the remaining commits.
📐

Syntax

The basic commands to continue a rebase after a conflict are:

  • git add <file>: Mark the conflicted file as resolved after manual editing.
  • git rebase --continue: Continue the rebase process after resolving conflicts.
  • git rebase --abort: Cancel the rebase and return to the original branch state if needed.
bash
git add <file>
git rebase --continue
💻

Example

This example shows how to continue a rebase after a conflict occurs:

  1. Start a rebase: git rebase main
  2. Git stops due to conflict in app.js.
  3. Edit app.js to fix the conflict.
  4. Mark the file resolved: git add app.js.
  5. Continue the rebase: git rebase --continue.
bash
git rebase main
# Conflict occurs in app.js
# Manually edit app.js to fix conflict

git add app.js
git rebase --continue
Output
First, rewinding head to replay your work on top of it... Applying: Your commit message CONFLICT (content): Merge conflict in app.js # After fixing conflict and adding file: Applying: Your commit message Successfully rebased and updated refs/heads/your-branch
⚠️

Common Pitfalls

Common mistakes when continuing a rebase after conflict include:

  • Not editing the conflicted files before running git add.
  • Running git rebase --continue without staging the resolved files.
  • Forgetting to resolve all conflicts in all files.
  • Using git rebase --abort unintentionally, which cancels the entire rebase.
bash
git rebase main
# Conflict in app.js
# Wrong: git rebase --continue (without fixing or adding files)
# Correct:
# 1. Fix conflict in app.js
# 2. git add app.js
# 3. git rebase --continue
📊

Quick Reference

CommandPurpose
git add Mark conflicted file as resolved
git rebase --continueContinue rebase after resolving conflicts
git rebase --abortCancel rebase and restore original state

Key Takeaways

Always manually fix conflicts in files before staging them with git add.
Use git rebase --continue to proceed after resolving conflicts.
If unsure, git rebase --abort cancels the rebase safely.
Do not run git rebase --continue without staging resolved files.
Check all conflicted files are resolved before continuing.