A merge conflict happens when two branches changed the same lines of the same file, and Git can't decide which version is correct — so it stops and asks you. It's not an error or a sign you did something wrong; it's Git refusing to silently throw away someone's work.
What you'll see in the file:
```
<<<<<<< HEAD
the version on your current branch
=======
the version from the branch you're merging in
>>>>>>> feature-branch
```
How to resolve it, step by step:
1. Run `git status`. It lists exactly which files are conflicted. Nothing is lost or broken at this point — you're in a paused merge.
2. Open each conflicted file and find the `<<<<<<<` markers.
3. Decide what the correct final content is. Sometimes it's your version, sometimes theirs, and quite often it's a combination — you have to actually read both and think, which is why this can't be automated.
4. Delete all three marker lines (`<<<<<<<`, `=======`, `>>>>>>>`) and leave only the final correct code. Leaving a marker behind is the classic mistake; it produces a syntax error that's confusing if you don't know to look for it.
5. `git add <file>` for each resolved file, then `git commit`. Git pre-fills a merge commit message; accept it.
6. Run the code. Conflict resolution is a manual edit, so verify the result actually works rather than assuming.
The escape hatch, which is what you should have known before panicking: `git merge --abort` returns you to exactly where you were before the merge started. Nothing lost. Same for `git rebase --abort`. Knowing this exists removes most of the fear — you can always back out and try again.
Make your life easier with a visual tool: VS Code shows conflicts with 'Accept Current / Accept Incoming / Accept Both' buttons and a side-by-side view, which is far less error-prone than editing markers by hand. Most editors and Git GUIs have equivalents.
How to get fewer conflicts in the first place:
- Pull frequently. Conflicts get harder the longer branches diverge — a branch that's a week behind will conflict much more than one that's an hour behind.
- Keep branches short-lived and focused on one change.
- Avoid reformatting whole files alongside logic changes; a formatting-only commit turns every line into a potential conflict.
One reassurance: everyone panics at their first conflict, and resolving them becomes routine within a handful of repetitions. It's a five-minute task once you've done it three times.