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).
How conflicts appear in a PR
Section titled “How conflicts appear in a PR”If your branch conflicts with main, GitHub displays a warning on the PR page:
This branch has conflicts that must be resolvedThe Merge pull request button is disabled until the conflict is resolved.
Option 1 — Resolve locally (recommended)
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:
git switch feature/trail-difficultygit pull origin mainThis 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.txtAutomatic merge failed; fix conflicts then commit the result.Step 2 — Open the conflicted file and look for markers:
<<<<<<< HEADDifficulty: 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:
git add pine-ridge.txtgit commit -m "Merge main into feature branch, resolve difficulty rating conflict"Step 5 — Push the branch:
git pushThe 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:
- On the PR page, click Resolve conflicts
- GitHub opens a file editor with the conflict markers visible
- Edit the file to remove the markers and leave the correct content
- Click Mark as resolved for each file
- 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.
Preventing conflicts
Section titled “Preventing conflicts”Conflicts are unavoidable on active teams, but you can reduce them:
- Pull
mainfrequently — 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
Understanding what caused the conflict
Section titled “Understanding what caused the conflict”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.
Exercise
Section titled “Exercise”You will simulate a conflict manually:
-
Make sure you are on
mainand it is up to date:git pull -
Create a feature branch:
git switch -c feature/conflict-practiceecho "Season: Summer" >> pine-ridge.txtgit add pine-ridge.txtgit commit -m "Add season recommendation"- Switch back to main and make a conflicting change:
git switch mainecho "Season: Spring" >> pine-ridge.txtgit add pine-ridge.txtgit commit -m "Add spring season note"git push- Push the feature branch and open a PR:
git switch feature/conflict-practicegit push -u origin feature/conflict-practice-
On GitHub, open a PR from
feature/conflict-practiceintomain. You should see the conflict warning. -
Resolve the conflict locally:
git pull origin main# edit pine-ridge.txt to resolve the conflict markersgit add pine-ridge.txtgit commit -m "Resolve season conflict — keep Summer as recommendation"git push- On GitHub, confirm the conflict warning is gone. Merge the PR.
- Conflicts in a PR appear when
mainand your branch changed the same lines. - Resolve locally: pull
maininto 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
mainfrequently and keeping branches short-lived.
Next: pull request best practices — good descriptions, small focused PRs, and how to give and receive feedback professionally.