devlk
c/learning u/devlk Team

How do I resolve a merge conflict without panicking?

Team FAQ: this question comes up often, so we've answered it below. Add your own experience, or a different view, in the comments.

You run git merge or git pull and Git says "CONFLICT (content): Merge conflict in ...". What now?

1
1 comment
No account needed: you'll get a random guest name, kept on this device. Or sign up to choose yours.
Sort by: Best Top New Old
devlk Team·

A conflict just means two branches changed the same lines, and Git wants you to choose. Nothing is lost.

Step by step:

  1. Run git status to see which files are conflicted ("both modified").
  2. Open each file. You'll see markers like this:
<<<<<<< HEAD
const timeout = 3000;
=======
const timeout = 5000;
>>>>>>> feature/retry

The top part is your current branch; the bottom part is the branch you're merging in.

  1. Edit the code so it's correct. Keep one side, the other, or combine them. Then delete all the marker lines.
  2. Mark it resolved and finish:
git add path/to/file
git commit        # for a merge
# or: git rebase --continue   (if you were rebasing)

Changed your mind? git merge --abort (or git rebase --abort) puts everything back to how it was before.

Tips:

  • Use an editor that helps. VS Code shows "Accept Current / Incoming / Both" buttons and a 3-way merge editor. JetBrains IDEs have a similar tool.
  • Run the tests after resolving. Code can merge cleanly and still be broken.
  • Prevent big conflicts: keep branches short-lived and merge or rebase from main often.
  • If you don't understand the other change, ask its author. That's normal and faster than guessing.

Got a tip that makes conflicts easier? Add it below.

1