Git Branches, Pull Requests and Merge Conflicts

Two developers work on the same booking app. One increases the maximum number of seats per request. The other fixes a problem that allows customers to request zero seats.

Both changes are useful. But if they edit the same condition differently, how should the application combine them?

Branches, pull requests and merge conflicts describe different parts of that collaboration. A branch organises a line of development. A pull request proposes integrating changes for review. A merge conflict occurs when Git cannot automatically combine particular changes.

We will follow one booking feature through all three, starting with an everyday analogy before looking at the code and commands.

Think of Two Editors Revising the Same Instructions

Imagine two people editing workshop instructions from the same starting document.

One changes “maximum two attendees per booking” to “maximum five.” The other adds that every booking must include at least one attendee.

They need a way to prepare their changes separately, show the proposed revisions and agree on the combined wording.

In an app project, branches support separate development histories. A pull request provides a place to discuss the proposed integration. Merging brings the histories together.

If Git cannot combine an overlapping edit automatically, a developer must decide what the final content should be.

What Is a Git Branch?

A branch is a named reference to a commit. As new commits are added on that branch, the reference advances.

For everyday work, it helps to think of a branch as a line of development for a feature, fix or experiment.

A team might use:

  • main as its primary integration branch.
  • feature/booking-limit for a booking-limit change.
  • fix/booking-validation for an input-validation fix.

These names are conventions. Calling a branch main does not automatically make its code correct, tested or published.

A branch is not another project folder

Creating a branch does not duplicate the entire application into a second folder. Git records the branch's position in the commit history.

Switching branches normally updates the working files to match the selected line of development.

Uncommitted edits are not automatically protected as separate branch history. Check and deliberately handle your working changes before switching or integrating work.

What Is a Pull Request?

A pull request, usually shortened to PR, proposes bringing changes from one branch into another.

On GitHub, it brings together the explanation, commits, changed files, review discussion and associated checks. Bitbucket also uses pull requests; GitLab calls its corresponding workflow a merge request.

A reviewer can inspect the proposed behaviour, ask questions and request changes before integration.

Source branch and target branch

For our booking feature:

  • Source or head branch: feature/booking-limit, containing the proposed work.
  • Target or base branch: main, which should receive it.

Checking this direction matters. A pull request targeting the wrong branch can propose a different integration from the one the team intended.

Pushing a branch does not complete a review

A normal Git push shares commits with the configured remote. On GitHub, opening a pull request is a separate action.

Likewise, opening a PR does not mean the change has been approved, merged or released to customers.

What Does Merging Mean?

Merging integrates another branch's history into the branch currently checked out.

For example, while working on a feature branch, merging origin/main brings the fetched main history into that feature branch.

Git can combine many changes automatically. When it cannot determine how to reconcile particular edits, it pauses for conflict resolution.

A pull request is one way to organise review around integration. Git itself can perform merges locally without a hosting platform or PR.

Follow One Booking Change From Branch to Pull Request

The following example assumes an existing Flutter project with Git configured, a remote named origin and an up-to-date local main branch. Start with a clean working tree.

The project contains lib/booking_rules.dart with this simplified rule:

bool canRequestSeats(int seats) {
  return seats <= 2;
}

This initial rule checks only the upper limit. It also contains a validation problem: zero and negative numbers pass that check.

1. Create the feature branch

From the up-to-date main branch, run:

git status
git switch -c feature/booking-limit

git status reports your current working state. git switch -c creates the new branch and switches to it.

2. Prepare the booking-limit change

Change the maximum from two seats to five:

bool canRequestSeats(int seats) {
  return seats <= 5;
}

This changes the upper limit, but the existing positive-quantity problem remains.

Record and share the feature change:

git add lib/booking_rules.dart
git diff --staged
git commit -m "Allow up to five seats per booking"
git push -u origin feature/booking-limit

The staged diff lets you inspect what the commit will contain. The push shares the branch, and -u establishes its upstream relationship.

3. Open the pull request

On GitHub, create a pull request with:

  • Base: main.
  • Compare: feature/booking-limit.
  • Title: “Allow up to five seats per booking.”

Explain why the limit changes and record the checks actually performed. Include relevant screenshots or behaviour examples when they help reviewers assess the work.

A useful description makes the proposed result understandable without requiring the reviewer to reconstruct the task from the diff.

How a Merge Conflict Appears

While the feature is under review, another developer fixes the positive-quantity problem. Their change reaches main:

bool canRequestSeats(int seats) {
  return seats > 0 && seats <= 2;
}

Now the branches have changed the same original line differently:

  • The feature branch allows up to five seats.
  • The updated main branch requires a positive quantity but retains the two-seat limit.

Git cannot automatically choose the intended combined rule. The PR can therefore report a merge conflict.

Conflicts can also involve a file deleted on one branch and edited on another. They are not limited to competing changes on one line.

Resolve the Conflict on the Feature Branch

For this example, the feature is intended for main. We will bring the latest main changes into the feature branch and submit the resolved result through the existing PR.

1. Fetch the latest remote information

With no unrelated uncommitted work, run:

git switch feature/booking-limit
git fetch origin
git merge origin/main

git fetch origin updates the available remote-tracking information. It does not itself merge that information into the feature.

git merge origin/main then attempts the integration. The active branch is still feature/booking-limit, so this operation does not merge the feature into main.

2. Identify the conflicted file

git status

Git reports unmerged paths. In our example, it identifies lib/booking_rules.dart.

The merge remains in progress while you resolve the conflict.

3. Read the conflict markers

With the standard merge conflict display, the file contains:

bool canRequestSeats(int seats) {
<<<<<<< HEAD
  return seats <= 5;
=======
  return seats > 0 && seats <= 2;
>>>>>>> origin/main
}

In this specific merge:

  • HEAD represents the checked-out feature branch.
  • The first block contains its five-seat condition.
  • The second block comes from origin/main.
  • The marker lines separate the alternatives Git could not combine.

Do not assume that an editor's “current” or “incoming” label always means the same branch in every operation. Read the operation and branch names, especially when comparing merge and rebase workflows.

4. Write the required final behaviour

The intended result must satisfy both requirements: at least one seat and no more than five.

Replace the conflicting block and remove all marker lines:

bool canRequestSeats(int seats) {
  return seats > 0 && seats <= 5;
}

Accepting the feature version unchanged would lose the positive-quantity fix. Accepting the main version unchanged would lose the five-seat limit.

Conflict resolution therefore requires understanding the requirements, not simply choosing whichever block appears first.

5. Check the combined behaviour

For this rule, relevant boundary cases include:

  • -1 and 0: rejected.
  • 1 and 5: accepted.
  • 6: rejected.

Update or add relevant tests where necessary. In a Flutter project with the SDK and dependencies available, run the project's checks, such as:

flutter analyze
flutter test

Also inspect the related screen and backend contract where appropriate. A correct local helper does not establish that the full booking flow handles the rule consistently.

6. Record and push the resolution

git diff --check
git add lib/booking_rules.dart
git diff --staged
git commit -m "Merge main and preserve both booking rules"
git push origin feature/booking-limit

git diff --check helps detect issues such as introduced conflict markers and whitespace errors. It does not validate business behaviour.

Staging the corrected file marks its conflict as resolved for Git. The commit completes this merge, and the push updates the branch used by the PR.

Review the updated PR and its checks before integration. Repository rules may require renewed approval after changes. If the target branch changes again, further integration work may be necessary.

Does “No Conflicts” Mean the Code Works?

No. Git can combine text without understanding the complete application behaviour.

For example, a mobile change might send a new request field while the backend still expects the old format. Because the changes live in different files or repositories, Git may report no textual conflict.

The integrated feature can still fail when the app makes the request.

Review, automated checks and appropriate integration testing address questions that automatic text merging cannot answer.

What Should a Reviewer Check?

A review should connect the proposed change with its intended result:

  • Does the code implement the stated requirement?
  • Are important boundary and failure cases covered?
  • Does the change remain compatible with related code and APIs?
  • Did conflict resolution preserve the required behaviour from both sides?
  • Do the reported checks correspond to the current proposed version?
  • Are unrelated changes making the review harder?

Small, coherent PRs help reviewers answer these questions. A change touching several files can still be coherent when those files serve one purpose.

For a solo developer, a PR can provide a structured self-review and a record of checks. Self-review does not provide an independent second opinion, but the workflow can still make decisions easier to inspect later.

How to Reduce Avoidable Merge Conflicts

Keep changes focused and integrate regularly

Long-running branches can accumulate differences from their target. Smaller pieces of work and regular integration make those differences easier to understand.

Coordinate changes to shared files

Tell teammates when a task will rename shared components, change an API contract or reorganise a commonly edited file.

Clear responsibilities within app code also make it easier to identify which parts a change should affect.

Separate broad formatting from behaviour changes

Combining a large formatting rewrite with a small logic change creates extra material to inspect and can increase overlap with other work.

Use branch rules that fit the project

Hosting platforms can enforce requirements such as review approvals and status checks before integration. Configure these around the project's actual needs.

These practices reduce avoidable problems. They do not guarantee a conflict-free project, and a conflict is not automatically evidence of poor work.

Merge Commits, Squash Merges and Rebases

Teams can integrate proposed work using different history strategies:

  • Merge commit: joins histories while retaining their relationship through a merge commit.
  • Squash merge: combines the PR's changes into one new commit on the target branch.
  • Rebase: reapplies work on another starting point, generally creating replacement commits.

The local conflict-resolution example above uses a merge. A rebase workflow has different continuation commands and history implications.

Choose the repository's agreed approach rather than mixing instructions from different workflows. On hosting platforms, the final PR merge method also depends on the options enabled for that repository.

What If the Feature Must Target More Than One Branch?

Some teams maintain separate development and release branches. A feature may need integration with both.

In that arrangement, merging an entire development branch into the reusable feature branch can introduce unrelated commits that are unsuitable for a later release target.

The simple feature-to-main example should therefore not be applied blindly. A dedicated integration branch or another planned approach may be appropriate.

Identify the intended destinations and agree the integration strategy with the maintainers before changing the branch's ancestry.

Frequently Asked Questions

Is a pull request the same as git pull?

No. A pull request proposes integration through a collaboration platform. git pull fetches repository information and integrates changes locally according to the selected options or configuration.

Can I create a branch without GitHub?

Yes. Branches are part of Git. GitHub provides hosting and collaboration features around them.

Should I always choose “accept both” in a conflict editor?

No. Keeping both blocks can duplicate code or produce incorrect behaviour. In the booking example, the final result is one combined condition rather than two competing return statements.

Can I stop a merge before completing it?

For an in-progress merge, git merge --abort attempts to restore the pre-merge state. Starting with a clean working tree makes that recovery more predictable; unrelated uncommitted edits can complicate it.

Does resolving a conflict merge the pull request?

Not in the workflow shown here. We resolve the conflict on the feature branch and push it for further review. Integrating that PR into its target remains a separate step.

Does merging into main publish the app?

Only if the project's configured delivery workflow performs that action. Mobile builds, store submissions and backend deployments have their own release processes.

Combine the Required Behaviour, Then Review the Result

For each integration, identify the source branch, target branch and intended behaviour. If Git reports a conflict, inspect both changes and decide what the application should do after they are combined.

In the booking example, the correct resolution preserves both the positive-quantity rule and the five-seat maximum. The PR then provides a place to review that result before it reaches the shared branch.

If your MVP is growing or an existing app needs a clearer collaboration and release process, explore Damien Musy's expertise for support reviewing code organisation, integration practices and the workflow used to deliver changes.