🔧 Error Fixes
· 2 min read
Last updated on

Git Rebase Conflict — How to Fix It


CONFLICT (content): Merge conflict in file.js. Could not apply commit

What causes this

During a rebase, Git replays your commits one by one on top of the target branch. When one of your commits changes the same lines that were also changed in the target branch, Git can’t decide which version to keep — that’s a conflict.

Rebase conflicts are more common than merge conflicts because each commit is applied individually. If you have 5 commits that touch the same file, you might need to resolve conflicts 5 times.

Fix 1: Resolve the conflict and continue

When you hit a conflict during rebase, Git pauses and marks the conflicting files:

# See which files have conflicts
git status

# Open the conflicting file — look for conflict markers
<<<<<<< HEAD
const port = 3000;
=======
const port = process.env.PORT || 8080;
>>>>>>> your-commit-message

Edit the file to keep the code you want, removing the conflict markers. Then:

git add file.js
git rebase --continue

Git will move to the next commit. Repeat if more conflicts appear.

Fix 2: Abort the rebase entirely

If things get messy and you want to start over:

git rebase --abort

This puts you back exactly where you were before the rebase started. No changes lost.

Fix 3: Skip a problematic commit

If a specific commit is causing conflicts and you don’t need it:

git rebase --skip

This drops the current commit and continues with the rest. Use carefully — make sure you actually don’t need that commit’s changes.

Fix 4: Use a merge tool

For complex conflicts, a visual tool helps:

git mergetool

# Or use VS Code directly
code --wait file.js

Configure your preferred tool:

git config --global merge.tool vscode
git config --global mergetool.vscode.cmd 'code --wait $MERGED'

Fix 5: Interactive rebase to squash first

If you have many small commits causing repeated conflicts, squash them first:

# Squash your commits into fewer, cleaner commits
git rebase -i HEAD~5

# Mark commits as 'squash' or 'fixup' in the editor
# Then rebase onto the target branch
git rebase main

Fewer commits means fewer potential conflict points.

Fix 6: Use merge instead of rebase

If rebase conflicts are too painful, merge is a valid alternative:

git merge main
# Resolve conflicts once, not per-commit

You lose the linear history but only deal with conflicts once.

How to prevent it

  • Rebase frequently — the longer your branch diverges from main, the more conflicts you’ll hit
  • Keep commits small and focused on one change
  • Communicate with your team about which files you’re working on
  • Use git pull --rebase regularly to stay up to date
  • Check our Git cheat sheet for rebase workflow patterns
📘