How to Split and Fold Pull Requests

Learn how to split and fold pull requests in our how-to guide. It's helpful when you accidentally create a large pull request and must split it for code review.

Occasionally you might accidentally create a large pull request. In order to do an effective code review, you want to split such large PRs. Aviator CLI allows you to split them.

Overall Workflow

In Aviator CLI, one branch corresponds to one PR. To split a large pull request, we take two steps:

  1. Split a large commit into multiple commits.

  2. Reorder and split commits into stacked branches.

By using Split a Commit feature, you can split a large commit into pieces. The guide below walks you through how to reorder and split those commits.

Setup

Let's use Hello-World repository as an example.

$ git clone https://github.com/octocat/hello-world hello-world
$ cd hello-world
$ av init
$ touch myfile
$ git add myfile

Then, create one branch.

$ av branch stack-1
$ echo 1a >> myfile
$ git commit -m 1a myfile
$ echo 1b >> myfile
$ git commit -m 1b myfile
$ echo 2a >> myfile
$ git commit -m 2a myfile
$ echo 2b >> myfile
$ git commit -m 2b myfile

This creates 4 commits.

Split the branch

Run av reorder. It opens an editor and shows the initial reordering plan.

Currently, we have a branch stack-1, branched off from master. We will move the commit 2a and 2b into stack-2. To do this, change the plan into following:

Save and close the editor. Aviator CLI picks up the commit 1a and 1b on stack-1 and picks up the commit 2a and 2b on stack-2.

This creates a commit graph like this.

Fold the branches

The opposite operation is possible as well. Run av reorder again.

Remove stack-branch stack-2 --parent stack-1, save, and exit.

This time, since we removed the branch stack-2 from the plan, it prompts you what to do with that branch. Since we do not need it anymore, we choose "Delete the branches".

The branch stack-1 now has the commit 1a through 2b.

Last updated

Was this helpful?