Real-world examples of merge conflict handling examples in GitHub

If you write code with other humans, you will hit merge conflicts. The good news: once you’ve seen a few real examples of merge conflict handling examples in GitHub, they stop feeling mysterious and start feeling like a routine part of collaboration. This guide walks through practical, GitHub-focused scenarios instead of abstract theory. We’ll walk through realistic examples of how conflicts show up in pull requests, how GitHub’s web editor and command line both present them, and what clean resolution actually looks like. Along the way, you’ll see an example of a simple text conflict, an example of a nasty rebase gone wrong, and several examples that include binary files, documentation, and protected branches. The goal is to help you read conflict markers with confidence, make smart decisions about whose changes win, and avoid reintroducing bugs while you’re fixing history. If you’ve ever stared at `<<<<<<< HEAD` and felt stuck, these GitHub-centered stories are for you.
Written by
Jamie
Published

GitHub-first examples of merge conflict handling examples in GitHub

Let’s start with what people actually see in the wild: pull requests, green checks, and that dreaded orange “This branch has conflicts that must be resolved.” These are not theoretical puzzles; they’re usually the result of very normal team behavior.

Imagine a small team working on a feature/login branch while someone else ships a hotfix directly to main. Both touch the same auth.js function. When the login feature is ready, the pull request looks good, but GitHub blocks the merge. This is the classic GitHub conflict scenario: the code compiles, tests pass locally, but the history doesn’t line up.

In these examples of merge conflict handling examples in GitHub, the pattern is always the same:

  • GitHub detects competing edits in the same lines or nearby lines.
  • It inserts conflict markers in the file if you resolve locally, or shows side‑by‑side chunks in the browser.
  • You decide which edits stay, which go, and what the final combined version should be.

The rest of this article walks through specific, real examples and shows how to resolve them without breaking your team’s flow.


Example of a simple text merge conflict in a GitHub pull request

The most common example of merge conflict handling examples in GitHub is two developers editing the same function in slightly different ways.

Say main has this code in discounts.js:

function calculateDiscount(total) {
  return total * 0.1; // 10% discount
}

Developer A, on feature/black-friday, changes it to:

function calculateDiscount(total) {
  return total * 0.25; // 25% Black Friday discount
}

Developer B, on feature/loyalty-tier, changes it to:

function calculateDiscount(total) {
  if (total > 200) return total * 0.15;
  return total * 0.1;
}

When both branches are merged via pull requests, GitHub flags a conflict. If you resolve it locally, you’ll see:

function calculateDiscount(total) {
<<<<<<< HEAD
  if (total > 200) return total * 0.15;
  return total * 0.1;
=======
  return total * 0.25; // 25% Black Friday discount
>>>>>>> feature/black-friday
}

The correct resolution might be a combined version:

function calculateDiscount(total) {
  const baseRate = total > 200 ? 0.15 : 0.1;
  const isBlackFriday = process.env.BLACK_FRIDAY === 'true';
  const finalRate = isBlackFriday ? 0.25 : baseRate;
  return total * finalRate;
}

You commit this resolved file, push to the branch, and GitHub updates the pull request automatically. This is one of the best examples of how conflict markers are a starting point, not a decision: you often need a third, merged idea.


Web editor vs CLI: two examples of merge conflict handling in GitHub

Another useful example of merge conflict handling examples in GitHub is comparing how the same conflict feels in the browser versus on the command line.

In the browser, GitHub shows a “Resolve conflicts” button on the pull request. Click it, and you get a side‑by‑side editor with <<<<<<< and >>>>>>> markers already in place. For smaller changes, especially in documentation or configuration, this is fast and safe. You pick the right lines, edit the combined version, mark as resolved, and commit from the UI.

On the command line, the workflow is different:

git fetch origin
git checkout feature/black-friday
git merge origin/main
## or: git rebase origin/main

Git stops at the conflict, and you open the file in your editor. Many modern IDEs (VS Code, JetBrains, etc.) highlight the sections and offer buttons like “Accept Current Change” or “Accept Incoming Change.” This local example of conflict handling is better when you need tests, refactors, or multiple file edits together.

A lot of teams in 2024–2025 use a hybrid style: trivial conflicts resolved in the GitHub UI, complex logic conflicts resolved locally with a full test run. The examples include monorepos with dozens of packages where resolving conflicts without running tests is asking for trouble.


Real examples of merge conflict handling examples in GitHub for documentation

Not every conflict is about code. A surprisingly common example of merge conflict handling examples in GitHub shows up in README.md or CHANGELOG.md.

Picture this:

  • Developer C updates the README to add a new section on local setup.
  • Developer D updates the same README to document a new API endpoint.

Both prepend a section at the top of the file. When the second pull request lands, GitHub reports a conflict. The content is fine; the problem is both edits touched the same region.

The resolution here is usually straightforward: keep both sections and adjust the order. For example, you might put “Quick Start” first, then “Local Setup,” then “API Reference.” This kind of conflict is a good candidate for GitHub’s web editor because the risk of breaking builds is low, and the context is easy to see.

These documentation‑first examples of merge conflict handling examples in GitHub are a good training ground for junior developers: they learn to recognize the markers and the workflow without risking production code.


Binary files and design assets: tricky examples include images and PDFs

Binary files are where merge conflict handling gets awkward. You can’t open a PNG with conflict markers. Instead, GitHub simply tells you “This file has conflicts” and forces you to pick one version.

Consider a design repo where two designers independently update homepage-hero.png on branches new-branding and holiday-theme. When both branches are ready to merge, GitHub can’t automatically combine the pixels. You get a conflict that must be resolved by choosing one version or renaming files.

A realistic example of conflict handling here:

  • Rename the new asset on one branch to homepage-hero-holiday.png.
  • Update the code or HTML to reference the right asset.
  • Commit the change and push.

For audio, video, or large documents, teams often avoid these conflicts by using Git LFS or storing assets in a separate system entirely. Even in 2025, most of the best examples of GitHub conflict handling still focus on text; binary conflicts are usually resolved by human decision, not merging.


Rebase vs merge: real examples of conflicts during history cleanup

Another class of examples of merge conflict handling examples in GitHub happens before the pull request is even opened: during git rebase.

Say you’re on feature/reporting and your team requires a linear history. Before opening a pull request, you run:

git fetch origin
git rebase origin/main

If main has moved significantly, you might hit conflicts in several commits. Each stop during the rebase shows the same conflict markers, but now you’re rewriting your own history instead of merging two branches.

A concrete example:

  • Commit 1 on your branch renamed a function.
  • Commit 2 on main refactored that same function into a different module.

During rebase, you’ll resolve the conflict as if you were merging, but then you run git rebase --continue. When you finally push, GitHub sees a clean, linear branch and often a simpler pull request diff.

Teams that care about code review quality in 2024–2025 often teach these rebase‑driven examples of merge conflict handling in GitHub because they reduce noise in PRs and make it easier for reviewers to focus on real logic changes.

For a deeper background on how Git merges work, the official Git documentation is still the best reference: https://git-scm.com/docs/git-merge.


Protected branches and CI: examples include conflicts plus failing checks

Modern GitHub workflows rarely stop at “merge successful.” Continuous integration (CI) and protected branches add another dimension. You might resolve a conflict correctly and still be blocked by tests.

Here’s a realistic example of merge conflict handling examples in GitHub on a protected main branch:

  • The project uses GitHub Actions to run linting and tests on every push.
  • The main branch requires PRs to be up to date with main and all checks passing.
  • You open a PR from feature/performance-tweaks.

Someone merges another PR first, and now your branch is behind and has conflicts. You:

  • Merge main into your branch locally.
  • Resolve conflicts in a couple of files.
  • Run tests locally, fix a failing test caused by a subtle interaction between the two changes.
  • Push the updated branch.

GitHub reruns CI, and only then does the “Merge” button become available. These real examples of conflict handling show why it’s not enough to mechanically delete conflict markers; you need to think about behavior and verification.

For teams in regulated environments (finance, health, government), this pattern is standard practice. While not GitHub-specific, organizations like the U.S. Digital Service and other .gov teams often publish engineering guidelines that emphasize code review and testing culture; see, for example, the technology playbook from the U.S. Digital Service for how they think about safe changes at scale.


Large teams and monorepos: best examples from 2024–2025 workflows

In 2024–2025, more organizations are running monorepos: one GitHub repository for many services. That increases the odds of conflicts, but it also produces some of the best examples of merge conflict handling examples in GitHub.

A typical pattern:

  • Team A updates a shared utility library in packages/utils.
  • Team B updates a service in services/billing and also tweaks packages/utils.
  • Both branches are open as pull requests for days, accumulating commits.

When one merges, the other almost always hits conflicts. The resolution often involves:

  • Pulling the latest main.
  • Merging or rebasing locally.
  • Running a targeted test suite (for example, only billing and utilities) to keep feedback fast.

Some teams adopt a “change ownership” convention: if you touch packages/utils, you ping a designated owner in the PR to help with conflict resolution decisions. These social patterns are as important as the Git commands themselves.

Engineering blogs from universities and research labs sometimes share these workflows publicly. For example, large open source projects hosted by organizations such as the Apache Software Foundation or major research universities often discuss their GitHub practices in technical reports or documentation.


How to practice: creating your own examples of merge conflict handling in GitHub

You don’t need a big team to get comfortable with this. You can create your own examples of merge conflict handling examples in GitHub in a sandbox repo:

  • Create a new repository on GitHub.
  • Clone it locally and create two branches from main, say branch-a and branch-b.
  • Edit the same lines in a file on both branches with different content.
  • Push both branches and open pull requests.

Merge one PR, then watch the second one turn orange with a conflict warning. Use the GitHub UI to resolve it once, then repeat the experiment using your local editor. You’ll quickly see that every example of conflict handling follows the same core pattern: identify the intent of each change, craft a final version that respects both (or intentionally discards one), and verify behavior.

For structured learning about version control concepts, many universities provide free Git tutorials. For instance, the Harvard University CS50 materials include Git and GitHub workflows in their curriculum, and they’re a good complement to hands‑on practice.


FAQ: common questions about real examples of merge conflict handling

Q: Can you give a simple example of a merge conflict in GitHub?
Yes. Two branches edit the same line differently, like changing a function’s return value in opposite ways. When the second branch’s pull request is opened, GitHub reports a conflict. You then edit the file (in the browser or locally), choose the correct behavior, remove conflict markers, commit, and push.

Q: Are there examples of avoiding merge conflicts entirely?
You can’t avoid them forever, but you can reduce them. Short‑lived branches, frequent pulls from main, feature flags instead of long‑running forks, and clear file ownership all lower the odds. These are indirect examples of handling conflicts by prevention rather than reaction.

Q: Is it safer to use GitHub’s web editor or the command line for conflict resolution?
For small, obvious changes (typos, documentation, simple config tweaks), the web editor is fine. For anything that affects logic, tests, or multiple files, resolving locally is safer because you can run tests and use your full IDE tooling.

Q: What’s an example of a bad way to resolve a merge conflict?
Blindly clicking “Accept incoming change” or “Accept current change” without reading the code or running tests. That often drops bug fixes, security patches, or performance improvements that were made on main while you were working on your branch.

Q: How do large open source projects handle constant conflicts?
They rely on clear contribution guidelines, code ownership, frequent rebasing, and automated testing. Maintainers often ask contributors to rebase onto the latest main and resolve conflicts before review. Many of the best examples of merge conflict handling in GitHub come from these projects’ documented workflows.


If you remember nothing else from these examples of merge conflict handling examples in GitHub, remember this: the conflict markers are not the problem; they’re just the highlighter. Your real job is to understand the intent behind each change and produce a final version that the whole team can live with.

Explore More Version Control Conflicts

Discover more examples and insights in this category.

View All Version Control Conflicts