DEV Community

Cover image for Commit To Code: Working with Pull Requests & Conflict Resolution
Shane Dsouza
Shane Dsouza

Posted on

Commit To Code: Working with Pull Requests & Conflict Resolution

📚 Git & GitHub Series

➡️ You're reading Part 5

⬅️ Part 4: Branching, Merging, Squashing & Rebasing


Working with Pull Requests & Conflict Resolution

Pull Requests (PRs) are the heart of collaborative coding. Whether you're working solo or on a team, understanding how to open, review, and resolve conflicts in PRs is a crucial skill.


What is a Pull Request?

A Pull Request (PR) is a request to merge code from one branch into another (usually into main). PRs are managed on platforms like:

  • GitHub
  • GitLab
  • Bitbucket

Think of a PR as saying:

“Hey team, I’ve finished some work. Can you review and approve it before we add it to the main codebase?”


Creating a Pull Request on GitHub

Step 1: Create a Feature Branch and Push Your Changes

git checkout -b feat/user-login
git add .
git commit -m "Add user login feature"
git push --set-upstream origin feat/user-login
Enter fullscreen mode Exit fullscreen mode

We then check the commit history:

gitlog

Step 2: Visit GitHub

GitHub will show:

“This branch is X commits ahead of main. Compare & pull request.”

Image description

Click Compare & pull request

Fill in:

  • A clear title
  • A description of what the PR does (Markdown and checklists work great!)

Image description

Click Create Pull Request


What Happens After Creating a PR?

  • Your teammates review your code
  • They may **comment, request changes, or **approve*
  • Once approved, it gets merged into main (usually with a regular or squash merge)

Conflict Resolution in Git

Conflicts happen when two branches change the same part of a file differently. Git can’t decide which version to keep, so it flags a merge conflict.


Resolving Conflicts Safely in a PR

Sometimes your PR shows conflicts with main after it's already created.

Strategy: Merge main into your PR branch
This keeps the PR alive and lets you fix conflicts cleanly.


Option A: Fix Inside Your PR Branch

git checkout feat/user-auth
git pull origin main
# Resolve conflicts
git add .
git commit -m "Resolve conflicts with main"
git push

Enter fullscreen mode Exit fullscreen mode

Option B: Fix Using a Temporary Helper Branch

This is cleaner and more review-friendly.

# Step 1: Switch to your PR branch
git checkout feat/user-auth

# Step 2: Create a helper branch
git checkout -b feat/user-auth-merge-fix

# Step 3: Merge main into it
git merge main
# OR rebase if preferred:
# git rebase main

# Step 4: Resolve conflicts
# Step 5: Commit the resolution
git add .
git commit -m "Resolved conflicts with main"

# Step 6: Push the helper branch
git push origin feat/user-auth-merge-fix
Enter fullscreen mode Exit fullscreen mode

Then, create a new PR from feat/user-auth-merge-fix → feat/user-auth.

Once merged, your original PR is conflict-free and ready to go.

Why This Strategy Works

  • Keeps your PR branch clean
  • Lets you resolve conflicts independently
  • Makes the fix reviewable as a separate PR

Simulating a Merge Conflict

1. From main, create a shared file:

echo "Hello World" > hello.txt
git add hello.txt
git commit -m "Initial hello.txt"
git push
Enter fullscreen mode Exit fullscreen mode

Image description

2. Branch A (Developer A):

git checkout -b feat/greeting
echo "Hello from branch A" > hello.txt
git commit -am "Branch A greeting"

Image description

3. Branch B (Developer B):

git checkout main
git checkout -b feat/salutation
echo "Hi from branch B" > hello.txt
git commit -am "Branch B greeting"
Enter fullscreen mode Exit fullscreen mode

Image description

4. Now merge both into main. The second merge will trigger:

CONFLICT (content): Merge conflict in hello.txt
Automatic merge failed; fix conflicts and then commit the result.
Enter fullscreen mode Exit fullscreen mode

Image description

Fixing the Merge Conflict

1. Open the conflicted file. You'll see:

Image description

2. Edit the file to combine or choose changes:

Image description

3. Mark it as resolved:

Image description

git add hello.txt
Enter fullscreen mode Exit fullscreen mode

4. Commit the resolved merge:

git commit -m "Resolve merge conflict between feat/greeting and feat/salutation"
Enter fullscreen mode Exit fullscreen mode

Image description


Best Practices for Conflict Resolution

  • Pull often from main to stay up-to-date:
git pull origin main --rebase
Enter fullscreen mode Exit fullscreen mode
  • Keep PRs small and focused
  • Use clear commit messages when fixing conflicts
  • Avoid editing the same file as others if possible

Wrapping Up

In this article, you learned:

  • What a Pull Request is and how to open one
  • How to handle team feedback and approvals
  • What merge conflicts are and how to resolve them
  • How to handle conflicts cleanly with helper branches
  • Best practices to reduce and manage merge conflicts

Using PRs effectively will help you collaborate confidently, maintain a clean main branch, and avoid headaches when merging code.

📚 More from the Series


Enjoyed this post?

Found this helpful? Drop a comment, share it with your team, or follow along for the next deep dive.

shanedsouza.com

Tiugo image

Modular, Fast, and Built for Developers

CKEditor 5 gives you full control over your editing experience. A modular architecture means you get high performance, fewer re-renders and a setup that scales with your needs.

Start now

Top comments (0)

👋 Kindness is contagious

Getting more out of DEV is just a sign‑in away—curate your feed, save articles, and enjoy dark mode.

Sign in now