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 --continueExample
This example shows how to continue a rebase after a conflict occurs:
- Start a rebase:
git rebase main - Git stops due to conflict in
app.js. - Edit
app.jsto fix the conflict. - Mark the file resolved:
git add app.js. - 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 --continueOutput
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 --continuewithout staging the resolved files. - Forgetting to resolve all conflicts in all files.
- Using
git rebase --abortunintentionally, 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
| Command | Purpose |
|---|---|
| git add | Mark conflicted file as resolved |
| git rebase --continue | Continue rebase after resolving conflicts |
| git rebase --abort | Cancel 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.