Error fixDevOps · 3 min read · Updated 4 Dec 2026

Git Merge Conflict: How to Resolve It Step by Step

Resolve Git merge conflicts calmly: what the conflict markers mean, how to fix them in the editor or terminal, finish the merge or rebase, and avoid them.

QUICK ANSWERA merge conflict happens when two branches change the same lines of a file (or one deletes a file the other edits) and Git cannot decide which version to keep. Git marks the file with <<<<<<<, ======= and >>>>>>> sections. Open each conflicted file, keep the right code and delete the markers, then git add the file and run git commit (for a merge) or git rebase --continue (for a rebase).
Git merge conflict: causes and how to resolve
Git merge conflict: causes and how to resolve

What the markers mean

<<<<<<< HEAD
timeout: 30
=======
timeout: 60
>>>>>>> feature/faster-retry

Between <<<<<<< HEAD and ======= is your current branch's version. Between ======= and >>>>>>> is the incoming branch's version. The fix is to write the final version you want and delete all three marker lines.

Resolve it step by step

  1. See which files conflict: git status lists them under "both modified".
  2. Open each file and search for <<<<<<<. Decide: keep yours, keep theirs, or combine both. Talk to the other developer if you are not sure.
  3. Delete every marker line, save the file, and run the tests or at least build it.
  4. Mark it resolved: git add <file>.
  5. Finish: git commit for a merge, or git rebase --continue for a rebase (repeat for each commit that conflicts).
  6. Changed your mind? git merge --abort or git rebase --abort returns everything to how it was before.
  7. Push. If you rebased a branch you had already pushed, use git push --force-with-lease, never plain --force.

Useful shortcuts

CommandWhat it does
git checkout --ours <file>Keep your version of a whole file
git checkout --theirs <file>Keep the incoming version of a whole file
git mergetoolOpen a visual 3-way merge tool
git diff --name-only --diff-filter=UList only the conflicted files
VS Code "Accept Current / Incoming / Both"Click to resolve each block

Careful: during a rebase, "ours" and "theirs" are swapped (ours is the branch you are rebasing onto).

How to have fewer conflicts

  • Pull or rebase on main often; small, short-lived branches conflict less.
  • Keep pull requests small and merge them quickly.
  • Agree on formatting (Prettier, Black, gofmt) so whitespace changes do not collide.
  • Do not reorganise or reformat a whole file in the same PR as a feature change.

Questions

Is a merge conflict an error?

No. It is Git asking you to choose. Nothing is lost; both versions are in the file until you decide.

Merge or rebase to update my branch?

Both work. Rebase gives a cleaner history but rewrites your commits, so only rebase branches no one else is building on. Follow your team's rule.