GtGit · Lesson 4 of 8

Merge Conflicts

Two branches edit the same line, then merge. Git can't guess which version you want — so it asks. Conflicts look scary; they're actually a simple text-editing chore.

When git can't auto-merge, it stops and marks the conflicting region in the file with conflict markers. Your job: open the file, pick (or combine) the versions, delete the markers, stage, commit. That's the whole procedure.

Text
<<<<<<< HEAD
const greeting = "Hello, world!";
=======
const greeting = "Hi there!";
>>>>>>> feature-branch

The part between <<<<<<< and ======= is YOUR side (current branch).
The part between ======= and >>>>>>> is THEIR side (branch being merged).
Bash
git merge feature-branch
# CONFLICT (content): Merge conflict in greeting.js

# 1. Open greeting.js, edit it to the final version,
#    removing all <<<< ==== >>>> markers.
# 2. Then:
git add greeting.js
git commit               # completes the merge

# Panic button — abandon the merge, back to before:
git merge --abort
✦ Tip
VS Code and most editors show conflicts with 'Accept Current / Accept Incoming / Accept Both' buttons — same edit, less typing. Small, frequent merges mean small, rare conflicts.