Data report"State of code review 2024" is now liveRead the full report
Merge a stack of PRs manually
Learn how to merge a stack of PRs outside of Graphite.

Note

For the best experience, we recommend merging a stack of pull requests through Graphite stack merge.


Merging with stack merge in the Graphite app saves a substantial amount of time. However, if you'd like to manually merge your PRs, merge the PRs in the stack one at a time:

  1. Merge the bottom PR of your stack into your trunk on the Graphite app (or through GitHub).

  2. Run gt sync from any branch of your stack to pull trunk to local, delete the merged branch, and restack the rest of your stack on trunk.

  3. From any branch in your stack, run gt submit to force push the restacked branches so the new bottom of your stack can be merged into trunk.

  4. Repeat until you've landed all of the branches in your stack.


Note

We recommend always merging from the bottom of the stack. While there are other techniques, we've found that this is the most intuitive and safest model for our users.

Merging in reverse order from the middle or top of the stack and collapsing all of the PRs into one is the fastest way to merge an entire stack, but there are a number of pitfalls for users—namely around syncing this merged state locally (to continue developing on any upstack PRs) or undoing these changes if a user decides not to merge a PR. This may lead to perilous situations where users have felt like they've lost code or can't re-create their previous state.

While certainly not impossible, it's also harder to re-derive the original stack of PRs when looking at the git history.


To help prevent accidental mid-stack merges, Graphite creates an optional status check on GitHub for upstack PRs. This status check fails for all upstack PRs, and passes for all base PRs.

Since it's an optional check by default, you can still merge mid-stack if needed.

To configure this status check for your GitHub org:

  • Open the Graphite web app's settings page

  • Select the "Mergeability checks" page

  • Edit the Mergeability check on GitHub setting

Teams can make this check required in order to fully prevent merging PRs in a stack out of order:

  • In GitHub, if you don't have one already, create a branch protection rule targeting *

    • Enable Allow forces pushes

    • Caution: when adding a new rule, by default it'll add branch restrictions that didn't previously exist, blocking common workflows on development branches. To avoid that, make sure to also:

  • In Graphite, edit the Mergeability status check on GitHub setting to "Run on all PRs"

  • Make the mergeability check required on GitHub using the branch protection rule

Note: this cannot be enforced via GitHub rulesets due to limitations rulesets functionality: you must enforce this using a branch protection rule.

Stay unblocked. Ship faster.
Experience the new developer workflow - create, review, and merge code continuously. Get started with one command.
Learn more

Give your PR workflow
an upgrade today

Stack easier | Ship smaller | Review quicker

Or install our CLI.
Product Screenshot 1
Product Screenshot 2