How to Resolve Merge Conflicts in a Git Pull Request

Merge conflicts are an inevitable part of collaborative software development. If you’ve ever submitted a pull request (PR) and seen the dreaded “This branch has conflicts that must be resolved” message, you’re not alone.

In this blog, we’ll break down:

  • What merge conflicts are
  • Why they happen
  • How to resolve them effectively in a Git pull request (on GitHub and locally)

🧠 What is a Merge Conflict?

A merge conflict occurs when Git can’t automatically reconcile differences between two branches. This usually happens when:

  • Two people edit the same line of code
  • One branch deletes a file the other modifies
  • Code structure diverges significantly between branches

When this happens in a pull request, Git will prevent the merge until you resolve the conflicts manually.


⚠️ Common Scenario

You created a feature branch (feature/login) and submitted a pull request to main. Meanwhile, someone else made changes to the same files and merged them into main. Now your PR is out of sync, and Git can’t auto-merge.


✅ How to Resolve Merge Conflicts in a Pull Request

🧩 Option 1: Resolve Conflicts Locally

This is the most reliable method, especially for complex changes.

Step 1: Checkout Your Feature Branch

git checkout feature/login

Step 2: Pull the Latest Changes from the Base Branch (e.g., main)

git fetch origin
git merge origin/main

You may see conflict markers (<<<<<<<, =======, >>>>>>>) in the affected files.

Step 3: Manually Resolve Conflicts

Open the conflicting files in your code editor and look for markers like:

<<<<<<< HEAD
console.log("Hello from your branch");
=======
console.log("Hello from main branch");
>>>>>>> main

Choose which code to keep, modify, or combine. Then remove the conflict markers.

Step 4: Mark the Conflicts as Resolved

After editing:

git add path/to/conflicted-file

Step 5: Commit the Merge

git commit -m "Resolve merge conflicts between feature/login and main"

Step 6: Push the Changes

git push origin feature/login

Now go back to the PR page—you should see that the conflicts are resolved.


🖥️ Option 2: Use GitHub’s Web Editor (for Simple Conflicts)

  1. Open your pull request on GitHub
  2. Scroll to the “This branch has conflicts” message
  3. Click “Resolve conflicts”
  4. Edit the file inline using GitHub’s editor
  5. Click “Mark as resolved”
  6. Commit the merge

✅ Use this method only for small, simple changes—large or multiple-file conflicts are better handled locally.


🧰 Tips to Avoid Merge Conflicts

  • Pull often: Keep your feature branch updated with the base branch (git pull origin main)
  • Communicate: Coordinate with your team to avoid editing the same files/lines
  • Smaller PRs: Short-lived, focused branches reduce the risk of conflicts
  • Rebase (advanced): Rebasing can help keep a clean history, but use with care

🧠 Summary

StepCommand/Action
Switch to your branchgit checkout feature/login
Fetch and merge maingit fetch origin + git merge origin/main
Resolve conflicts manuallyEdit files and remove markers
Mark files resolvedgit add .
Commit and pushgit commit + git push

🚀 Conclusion

Merge conflicts in pull requests can feel like a roadblock, but they’re just part of the development process. By understanding how to resolve them—especially using local tools—you gain more confidence and control over your Git workflow.

The key is to stay calm, follow the process, and use the right tools for the complexity of your conflicts.

Sharing Is Caring:

Leave a Comment