Conflicts are inevitable when multiple people work on the same codebase. With merge, you resolve all conflicts once at the end. With rebaseWhat is rebase?A Git operation that replays your branch's commits on top of another branch's latest commit, creating a linear history instead of a merge commit., you might resolve conflicts multiple times because Git replays your commits one at a time. Each commitWhat is commit?A permanent snapshot of your staged changes saved in Git's history, identified by a unique hash and accompanied by a message describing what changed. that touches a file also modified in the base branch can trigger a separate conflict.
This sounds worse than merge, but it has an advantage: each conflict is smaller and easier to understand because it involves only one commit's changes at a time. Knowing how to navigate rebase conflicts efficiently makes the difference between a smooth workflow and one where you give up and fall back to merge every time.
git rebase --skip when a conflict appears. Skipping discards that commit entirely. Unless you are certain the commit's changes are already present in the base branch, skipping means losing work. Always resolve conflicts manually first.Why conflicts happen during rebaseWhat is rebase?A Git operation that replays your branch's commits on top of another branch's latest commit, creating a linear history instead of a merge commit.
Rebase replays your commits one at a time on a new base. If you have 5 commits and 3 of them modify a file that also changed in main, you could have up to 3 separate conflicts:
Your commits:
1. Add user authentication
2. Fix typo in auth
3. Add password validation ← modifies login.js
4. Update error messages ← modifies login.js
5. Add tests
Main also modified login.js
Result: conflicts on commits 3 and 4Each conflict is scoped to a single commitWhat is commit?A permanent snapshot of your staged changes saved in Git's history, identified by a unique hash and accompanied by a message describing what changed., so you only need to reconcile that one commit's changes with the new base.
The conflict resolution workflow
When Git hits a conflict during rebaseWhat is rebase?A Git operation that replays your branch's commits on top of another branch's latest commit, creating a linear history instead of a merge commit., it stops and shows you a message:
$ git rebase origin/main
Auto-merging src/login.js
CONFLICT (content): Merge conflict in src/login.js
error: could not apply abc1234... Add password validation
hint: Resolve all conflicts manually, mark them as resolved with
hint: "git add/rm <conflicted_files>", then run "git rebase --continue".Step 1: see what is conflicting
git status
# You are currently rebasing branch 'feature' on 'main'.
# (fix conflicts and then run "git rebase --continue")
#
# Unmerged paths:
# both modified: src/login.jsStep 2: open the file and look at the conflict markers
<<<<<<< HEAD
// Code from main (the new base)
function login(username) {
return authenticate(username);
}
=======
// Code from your commit
function login(username, password) {
return authenticate(username, password);
}
>>>>>>> abc1234 (Add password validation)Step 3: resolve by editing the file
Keep what you need and delete the conflict markers:
// Combined version
function login(username, password) {
return authenticate(username, password);
}Step 4: stage and continue
git add src/login.js
git rebase --continueGit moves on to the next commitWhat is commit?A permanent snapshot of your staged changes saved in Git's history, identified by a unique hash and accompanied by a message describing what changed.. If that commit also conflicts, repeat the process.
Your options during a conflict
| Command | What it does | When to use |
|---|---|---|
git rebase --continue | Proceed to the next commit | After resolving and staging all conflicts |
git rebase --skip | Skip the current commit entirely | Only when the commit's changes are already in the base |
git rebase --abort | Cancel the entire rebase | When you want to start over or try a different approach |
git mergetool | Open a visual merge tool | When conflicts are complex and you prefer a GUI |
git rebase --abort is your safety net. If a rebase gets too messy, abort and you are back to exactly where you started. No data is lost.Strategies for minimizing conflicts
The best way to handle rebaseWhat is rebase?A Git operation that replays your branch's commits on top of another branch's latest commit, creating a linear history instead of a merge commit. conflicts is to prevent them in the first place:
Rebase early and often:
# Daily rebase keeps conflicts small
git fetch origin
git rebase origin/mainSmall, frequent rebases mean each one has fewer changes to reconcile. A weekly rebase on a fast-moving project can produce dozens of conflicts; a daily rebase usually produces zero or one.
Make small, focused commits:
| Commit style | Conflict experience |
|---|---|
| One giant commit per day | Massive, confusing conflicts |
| Small commits per logical change | Small, easy-to-understand conflicts |
Communicate with your team:
- Let teammates know when you are refactoringWhat is refactoring?Restructuring existing code to make it cleaner, more readable, or more efficient without changing what it does. shared files
- Coordinate large changes that touch many files
- Avoid two people modifying the same function at the same time
Complete walkthrough
A realistic scenario from start to finish:
# You are working on a feature
git checkout -b feature/payment
git commit -m "feat: add payment form"
git commit -m "feat: add validation"
# Meanwhile, main has evolved
git fetch origin
# Start rebase
git rebase origin/main
# Conflict on first commit!
# CONFLICT (content): Merge conflict in src/payment.js
# Resolve it
# (edit src/payment.js, remove conflict markers)
git add src/payment.js
git rebase --continue
# Second commit also conflicts!
# CONFLICT (content): Merge conflict in src/payment.js
# Resolve again
# (edit src/payment.js)
git add src/payment.js
git rebase --continue
# Successfully rebased and updated refs/heads/feature/paymentWhen rebaseWhat is rebase?A Git operation that replays your branch's commits on top of another branch's latest commit, creating a linear history instead of a merge commit. conflicts are too painful
Sometimes a rebase produces so many conflicts that it is not worth the effort:
# Abort the rebase
git rebase --abort
# Fall back to merge instead
git merge origin/mainThis is perfectly acceptable. Merge commits are not bad. They are just different. Choose the tool that makes sense for your situation. If a rebase would require resolving the same conflict across ten commits, a single merge resolution is often the pragmatic choice.
Quick reference
| Situation | Command |
|---|---|
| See conflicting files | git status |
| Resolve and continue | git add <files> then git rebase --continue |
| Skip a commit | git rebase --skip |
| Cancel the rebase | git rebase --abort |
| Prevent future conflicts | git fetch origin && git rebase origin/main (daily) |
| Fall back to merge | git rebase --abort then git merge origin/main |