Skip to content

How to Fix PR Merge Conflicts

← Back to Git


βš”οΈ How to Fix PR Merge Conflicts

Sometimes, when you raise a Pull Request (PR), GitHub may detect a conflict if the target branch has changed in a way that clashes with your feature branch.

πŸ“š Features

  • Scenario: Two developers modify the same file/line.
  • Resolution: You must resolve conflicts before merging.

1. Setup Conflict Scenario

Create a repository pullrequest-conflict. Create cat.txt with initial content:

1. In terms of development, the first year of a cat’s life is equal to the first 15 years of a human life. After its second year, a cat is 25 in human years. And after that, each year of a cat’s life is equal to about 7 human years.
2. Cats can rotate their ears 180 degrees.
3. The hearing of the average cat is at least five times keener than that of a human adult.
4. In the largest cat breed, the average male weighs approximately 20 pounds.
5. Domestic cats spend about 70 percent of the day sleeping. And 15 percent of the day grooming.

File List

Create a branch feature. Change line 2 angle to 150 in feature branch:

Updated Feature

Simulate Remote Change: Go to GitHub, switch to master, edit cat.txt, and change angle to 200. Commit.

Master Update

2. Create PR & Detect Conflict

Create a PR from feature to master.

Create PR

GitHub shows a conflict:

Conflict UI

Click Create pull request to proceed anyway.

PR Diff

PR Created

3. Fix Conflict Locally

Clone the repo and switch to feature:

git clone https://github.com/vigneshsweekaran/pullrequest-conflict.git
cd pullrequest-conflict
git checkout feature

Clone

Pull master into feature to reproduce and fix the conflict:

git pull origin master

Pull Master

Conflict detected:

Conflict Terminal

Resolve the conflict in cat.txt (e.g., keep 150):

Fixed File

Add, commit, and push the fix:

git add .
git commit
Commit Fix

Check logs:

git log
Log

Push to feature:

git push origin feature
Push Fix

4. Merge PR

Go back to GitHub. The PR now shows as mergeable.

Click Merge pull request -> Confirm merge.

Merge Button

Merged


πŸ–₯️ Fix from GitHub UI (Alternative)

You can also resolve simple conflicts directly in the browser.

Create a conflicting PR and click Resolve conflicts:

Resolve UI

Conflict Editor

Edit the file to remove markers and click Mark as resolved.

Resolved

Commit the merge:

Commit UI

Merge the PR:

Merge UI

Merged UI


🧠 Quick Quiz β€” PR Conflicts

#

If your PR has a conflict with the base branch, what is the standard way to fix it?


πŸ“ Want More Practice?

πŸ‘‰ Start Git Advanced Quiz (20 Questions)


πŸ“¬ DevopsPilot Weekly β€” Learn DevOps, Cloud & Gen AI the simple way.
πŸ‘‰ Subscribe here