Skip to content

Merge Conflicts in Pull Requests

A merge conflict in a pull request means someone else changed the same lines you changed in main between when you branched off and now. GitHub cannot automatically merge the two changes — it needs you to decide which version wins (or how to combine them).

If your branch conflicts with main, GitHub displays a warning on the PR page:

This branch has conflicts that must be resolved

The Merge pull request button is disabled until the conflict is resolved.

Section titled “Option 1 — Resolve locally (recommended)”

Resolving locally gives you your full editor and the ability to run any tests before pushing.

Step 1 — Pull the latest main into your branch:

Terminal window
git switch feature/trail-difficulty
git pull origin main

This fetches main from GitHub and merges it into your feature branch locally. If there are conflicts, Git pauses:

CONFLICT (content): Merge conflict in pine-ridge.txt
Automatic merge failed; fix conflicts then commit the result.

Step 2 — Open the conflicted file and look for markers:

<<<<<<< HEAD
Difficulty: Moderate
=======
Difficulty: Easy
>>>>>>> origin/main
  • <<<<<<< HEAD — your version (the feature branch)
  • ======= — divider
  • >>>>>>> origin/main — the incoming version from main

Step 3 — Edit the file to the correct result:

Remove the conflict markers and leave only what should be there:

Difficulty: Moderate (with some steep sections)

Step 4 — Stage and commit:

Terminal window
git add pine-ridge.txt
git commit -m "Merge main into feature branch, resolve difficulty rating conflict"

Step 5 — Push the branch:

Terminal window
git push

The PR on GitHub updates automatically. The conflict warning disappears and the Merge pull request button becomes active.

Option 2 — Resolve in GitHub’s web editor

Section titled “Option 2 — Resolve in GitHub’s web editor”

For simple conflicts (a few lines in one or two files), GitHub’s built-in conflict editor works:

  1. On the PR page, click Resolve conflicts
  2. GitHub opens a file editor with the conflict markers visible
  3. Edit the file to remove the markers and leave the correct content
  4. Click Mark as resolved for each file
  5. Click Commit merge when all conflicts are resolved

This creates a new commit on your branch directly from the web. Use this for genuinely simple cases — if the conflict requires understanding code logic or running tests, resolve it locally.

Conflicts are unavoidable on active teams, but you can reduce them:

  • Pull main frequently — the longer your branch lives without rebasing on main, the more likely conflicts become
  • Keep branches short-lived — feature branches that live for days rather than weeks have fewer conflicts
  • Communicate — if you and a teammate are both editing the same file, coordinate

Not all conflicts are your fault or your teammate’s fault — they are just two valid changes to the same place. The conflict resolution step is where you (and the other author, if needed) agree on what the final version should be.

Read both versions carefully. Sometimes you want one, sometimes the other, sometimes a combination.

You will simulate a conflict manually:

  1. Make sure you are on main and it is up to date: git pull

  2. Create a feature branch:

Terminal window
git switch -c feature/conflict-practice
echo "Season: Summer" >> pine-ridge.txt
git add pine-ridge.txt
git commit -m "Add season recommendation"
  1. Switch back to main and make a conflicting change:
Terminal window
git switch main
echo "Season: Spring" >> pine-ridge.txt
git add pine-ridge.txt
git commit -m "Add spring season note"
git push
  1. Push the feature branch and open a PR:
Terminal window
git switch feature/conflict-practice
git push -u origin feature/conflict-practice
  1. On GitHub, open a PR from feature/conflict-practice into main. You should see the conflict warning.

  2. Resolve the conflict locally:

Terminal window
git pull origin main
# edit pine-ridge.txt to resolve the conflict markers
git add pine-ridge.txt
git commit -m "Resolve season conflict — keep Summer as recommendation"
git push
  1. On GitHub, confirm the conflict warning is gone. Merge the PR.
  • Conflicts in a PR appear when main and your branch changed the same lines.
  • Resolve locally: pull main into your branch, fix the conflict markers in your editor, commit, push. This is the preferred method.
  • Resolve in GitHub: use the web editor for simple one-file conflicts.
  • After resolving and pushing, the PR conflict warning clears and you can merge normally.
  • Prevent conflicts by pulling main frequently and keeping branches short-lived.

Next: pull request best practices — good descriptions, small focused PRs, and how to give and receive feedback professionally.