Branch From the Right Base When Stacking PRs

📖 2 minutes read

When you have a feature that spans multiple PRs — say, PR #1 builds the core, PR #2 adds an enhancement on top — you need to stack them properly.

The mistake I see developers make: they branch PR #2 from master instead of from PR #1’s branch.

# ❌ Wrong — branches from master, will conflict with PR #1
git checkout master
git checkout -b feature/enhancement

# ✅ Right — branches from PR #1, builds on top of it
git checkout feature/core-feature
git checkout -b feature/enhancement

And the PR target matters too:

  • PR #1 targets master (or main)
  • PR #2 targets feature/core-feature (PR #1’s branch), not master

Once PR #1 is merged, you update PR #2’s target to master. GitHub and GitLab both handle this cleanly — the diff will shrink to just PR #2’s changes.

When to combine instead: If the PRs are small enough and touch the same files, sometimes it’s simpler to combine them into one branch. We do this when features are tightly coupled and reviewing them separately would lose context.

# Combining two feature branches into one
git checkout master
git checkout -b feature/combined
git merge feature/part-1 --no-ff
git merge feature/part-2 --no-ff

The goal is always the same: make the reviewer’s job easy. Small, focused PRs with clear lineage beat a single massive PR every time.

Daryle De Silva

VP of Technology

11+ years building and scaling web applications. Writing about what I learn in the trenches.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *