How to split a pull request into multiple PRs

Greg Foster
Greg Foster
Graphite software engineer
Try Graphite


Note

This guide explains this concept in vanilla Git. For Graphite documentation, see our CLI docs.


Table of contents

In collaborative software projects, large pull requests can be a bottleneck to the review process. Graphite's suite of tools offers a streamlined approach to divide a single large PR into multiple smaller PRs, facilitating faster reviews and improved code quality. This guide will walk you through the process of splitting a PR using Graphite's split and submit CLI commands.

  • Review efficiency: Shorter PRs are easier and quicker for reviewers to understand.

  • Focused discussions: Discussions can remain focused on specific changes rather than sprawling across multiple contexts.

  • Faster integration: Smaller PRs can be merged faster, reducing the risk of merge conflicts.

Before you begin splitting your PR, ensure that you have a clear understanding of how your changes can be logically grouped into separate, self-contained updates.

Graphite's gt split command allows you to create new branches for each group of changes that you want to turn into individual PRs.

  1. Identify Changes: Look at the changes in your current PR and decide how you want to group them.

  2. Run the Split Command: Execute gt split to start the interactive process.

  3. Create New Branches: Graphite will guide you through creating new branches for each set of changes.

Example command:

Terminal
gt split

Once you've split your changes into separate branches, you can use the gt submit command to open new PRs for each branch.

  1. Review stacks: Use gt stack to review the branches you’ve created.

  2. Submit the stacks: Execute gt submit to open a PR for each branch in your stack.

  3. Link PRs: Reference each new PR in the original PR to maintain context.

Example command:

Terminal
gt submit

With gt submit, you can efficiently open multiple PRs simultaneously, a powerful feature for handling complex features or refactorings that span across different parts of the codebase.

Splitting a large PR into multiple smaller ones can significantly enhance the review process. By leveraging Graphite's split and submit commands, developers can easily manage their PRs, resulting in a more efficient and effective development workflow. Adopt these practices to ensure your changes are integrated swiftly and without overwhelming your team.

For a deep dive into each command and more advanced usage, visit Graphite's official documentation.

To split up a big pull request using Graphite:

  1. Analyze your changes: Review all the changes in your current PR and identify logical groupings
  2. Use gt split: Run the interactive split command to create separate branches for each group of changes
  3. Review the split: Use gt stack to review the branches you've created
  4. Submit multiple PRs: Use gt submit to open individual PRs for each branch

The key is to group related changes together while ensuring each new PR is self-contained and reviewable on its own.

Group related changes together and isolate unrelated ones; aim for pull requests that are focused, easier to review, and no larger than a few hundred lines of code.

While this guide focuses on splitting PRs, you can also squash commits in your PRs:

  1. Interactive rebase: Use git rebase -i
  2. Graphite commands: Use gt rebase to clean up your commit history
  3. Before splitting: Consider squashing related commits before splitting to create cleaner, more logical groupings

Squashing is particularly useful when you have many small, incremental commits that should be combined before splitting into separate PRs.

Built for the world's fastest engineering teams, now available for everyone