Git & GitHub · Daily Workflow

Merge Conflicts

A conflict means two branches changed the same lines differently. Git can’t guess which is right, so it asks you.

Intermediate 5 min Lesson 11 of 19Shows Git 2.47 and GitHub.com as of 2026. GitHub changes its layout from time to time; button names stay the same.
Before you start:Pull Requests
0/19 in Git & GitHub
On this page · 5 min · Intermediate

Learning objectives#

  • Recognise when a conflict happens
  • Read conflict markers
  • Resolve conflicts in VS Code
  • Finish the merge with add and commit

Explanation#

Git merges most changes automatically. A conflict only happens when both branches edited the same lines (or one deleted a file the other edited).

Git marks the conflicting part in the file: <<<<<<< HEAD starts your version, ======= separates, >>>>>>> other-branch ends their version. The file is not usable until you remove the markers.

VS Code shows buttons above each conflict: Accept Current Change, Accept Incoming Change, Accept Both Changes, Compare Changes. Pick one or edit by hand, save, then stage the file and commit.

On GitHub, a PR with conflicts shows “This branch has conflicts that must be resolved” and a Resolve conflicts button for simple cases.

Step-by-step screens#

Drawings of github.com, the Git installer, VS Code and a terminal. GitHub changes its layout from time to time; the button names stay the same. The red numbers match the numbered actions under each picture; names on your computer will differ.

Loading pictures…

Code example: A conflict and its fix#

Shellterminal Illustrative
git switch feature/new-title
git merge main
# CONFLICT (content): Merge conflict in index.html


# index.html now contains:
# <<<<<<< HEAD
# <h1>Welcome to my portfolio</h1>
# =======
# <h1>Hello, I'm Asha</h1>
# >>>>>>> main


# Keep the line you want, delete the markers, save, then:
git add index.html
git commit -m "Merge main into feature/new-title"
Expected output
Auto-merging index.html
CONFLICT (content): Merge conflict in index.html
Automatic merge failed; fix conflicts and then commit the result.
[feature/new-title 4d5e6f7] Merge main into feature/new-title

This example is illustrative. Copy or download it and run it in your own environment; the expected output is shown above.

Step-by-step explanation#

  1. Merging main into the branch reveals the conflict early.
  2. HEAD is the branch you are on; below ======= is main’s version.
  3. Edit the file to the final text and remove all three markers.
  4. git add marks it resolved; git commit finishes the merge.

Real-world use case#

Two teammates both edit the page title. The second to merge resolves the conflict in VS Code in under a minute and the PR turns green again.

Common mistakes#

Committing the markers

Leaving <<<<<<< in the file breaks the page. Search for <<<<<<< before committing.

Panicking and deleting the folder

git merge --abort returns to the state before the merge.

Best practices#

  • Pull or merge main into your branch often
  • Keep branches short-lived
  • Talk to the teammate who made the other change
  • Run the app after resolving

Remember this#

<<<<<<< yours ======= theirs >>>>>>>

Edit, save, add, commit.

git merge --abort to undo.

Practice exercise#

Your task: Cancel a merge that went wrong and return to the state before it.

Show solution
Shell Illustrative
git merge --abort

Mini quiz#

Merge Conflicts quizMultiple choice Question 1 of 1

When does Git report a conflict?

Score so far: 0/0

Want more? Practise all Git & GitHub MCQs · Git & GitHub interview questions

My notes#

Saved in this browser.

Progress is saved in this browser. Sign in to sync.