How do you resolve a merge conflict?
Quick Answer
Git marks the conflicting sections with <<<<<<< HEAD / ======= / >>>>>>> branch. You edit each file to the correct combined result, remove the markers, git add the resolved files, and git commit (for merge) or git rebase --continue. git merge --abort backs out entirely.
Git puts conflict markers in the file showing my version, a separator, and the incoming version. I go through each one, work out what the correct merged result actually is — often it's a combination, not just picking one side — delete the markers, git add the file, and then commit or rebase --continue. Afterwards I build and run the tests, because a resolution that compiles can still be wrong. The best way to deal with conflicts is to avoid the big ones: keep branches small and short-lived and pull main in regularly.
- Understand both sides before choosing — don't just “accept theirs” blindly; the right answer is often a blend.
- Build and run the tests after resolving — a conflict resolution that compiles can still be logically wrong.
- Reduce conflicts: small, short-lived branches; rebase/merge
mainfrequently; agree on formatting so whitespace doesn't clash. git rerereremembers how you resolved a conflict and replays it if the same one recurs.