Skip to content

Lesson

Conflicts

Why conflicts happen, how to read markers, and how to complete the merge.

Intermediate 6 min read

Learning objectives

  • Understand what causes a conflict
  • Read conflict markers
  • Resolve and finish the merge

Overlapping edits

A conflict happens when two branches change the same lines differently since their common ancestor. Git cannot know which version you want, so it asks.

Reading markers

Git inserts markers: <<<<<<< HEAD shows your version, ======= separates, and >>>>>>> shows the incoming version. Edit the file to the final content you want, removing the markers.

Finishing

After editing, git add the file to mark it resolved, then git commit to complete the merge (or git rebase --continue during a rebase).

Try it yourself

interactive visualization

Empty folder

Run git init to create a repository.

Working directory

Clean — no uncommitted changes.

git add ↓

Staging area

Nothing staged. Run git add.

git commit ↓

Repository

No commits yet.

1/4Empty repositoryOpen in visualizer

Merge, resolve the marked file, stage it, and commit to finish.

Commands used

terminal
git merge feature
git add conflicted.ts
git commit -m "merge: resolve conflict"

Common mistakes

  • Leaving marker lines in the file.
  • Committing without testing the resolved result.

Best practices

  • Resolve conflicts one file at a time.
  • Re-run tests after resolving.

Mini challenge

Resolve a conflict by combining both changes rather than picking one side.

Open the visualizer to try it

Summary

  • Conflicts come from overlapping edits.
  • Markers show both sides.
  • Add + commit finishes the merge.
Next lessonRemotes