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.

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

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

2. Create PR & Detect Conflict¶
Create a PR from feature to master.

GitHub shows a conflict:

Click Create pull request to proceed anyway.


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

Pull master into feature to reproduce and fix the conflict:
git pull origin master

Conflict detected:

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

Add, commit, and push the fix:
git add .
git commit
Check logs:
git log
Push to feature:
git push origin feature
4. Merge PR¶
Go back to GitHub. The PR now shows as mergeable.
Click Merge pull request -> Confirm merge.


π₯οΈ Fix from GitHub UI (Alternative)¶
You can also resolve simple conflicts directly in the browser.
Create a conflicting PR and click Resolve conflicts:


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

Commit the merge:

Merge the PR:


π§ 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