Stacked PRs CLI
Last updated
Last updated
Aviator is a suite of productivity tools purpose-built to reduce friction in development workflows. av
is an open-source CLI built and managed by Aviator to interact with GitHub and Aviator service. The primary use case is creating and managing Stacked PRs.
The Stacked PRs CLI does not require creating an Aviator account and can be installed directly.
Stacked PRs are useful when you have a lot of code changes that are hard to review in a single PR. Stacked PRs let you break down the changes into smaller PRs that are "stacked" on top of each other, keeping code review manageable. This means you can keep working on the next bit of code related to a feature even while waiting for your previous PR(s) to pass CI, be approved, and merged!
For example, if PR1 is Add the /books/list route to the backend
and PR2 is Show the books list in the frontend
, we can stack PR2 on top of PR1. This means that you don’t have to wait for PR1 to be reviewed and merged before you can start PR2 (and they can even be reviewed by separate people!).
Learn more about the cultural implication of using Stacked PRs in our blog post.
You don’t need an Aviator account to start using the CLI. You can simply install the CLI using your OS package manager. For instance, on Mac you can use Homebrew:
For installation on other platforms or step by step guide, please checkout installation instructions.
av CLI needs a GitHub credential for creating and updating PRs. Install GitHub CLI, and av CLI will use the same credential for interacting with GitHub. Alternatively, you can use a GitHub Personal Access Token. See Create an Access Token.
Finally, initialize the repository so that CLI can start tracking your active branches.
Creating the first branch in the stack is just the same as creating any normal branch in your repository, except now you use the av CLI. The av stack branch
command requires one argument which is the name of the branch to create. This command will create a branch on top of the current branch.
To create the PR, also use the av pr create
command to ensure that the correct base branch is set in the PR.
For the next branch, we use the av stack branch
command again, except this time we're branching from bookstore-backend
instead of main
since we want to build off of our previous work. Behind the scenes, the CLI sets some internal data to be able to recognize that bookstore-frontend
is dependent on bookstore-backend
.
And when it comes time to submit our work as PR, we use the av pr create
command again.
When creating this PR, the CLI again automatically sets the base branch in GitHub as bookstore-backend
rather than main
to ensure that GitHub shows the diff between bookstore-frontend
and bookstore-backend
. Otherwise, it would show all the changes from bookstore-backend
in the PR for bookstore-frontend
which would make code review much harder.
Already have git branches created? Take a look at Adopt a Branch.
Since stacked PRs are designed to make code review easier and more incremental, it's likely that you'll need to change code that you wrote earlier in the stack. The av stack sync
command is used to make sure every branch is up-to-date with its stack parent.
To edit a branch that is part of a stack, first we need to check it out.
Then, we can make edits and commit as usual.
Finally, we can run av stack sync
to propagate the changes to all children branches.
Merging a stack with Aviator is a little different than merging a non-stacked PR. Although you can merge PRs now manually one at a time, the best way to merge the PRs is to use Aviator MergeQueue.
Aviator MergeQueue is purpose built as a highly scalable stack-aware merge queue. Follow these steps to connect the CLI with Aviator:
sign up for a free account with Aviator
walk through the initial steps, and install the Aviator app on GitHub
navigate to user access token page: https://app.aviator.co/account/apitoken
generate a token and add it to your configuration file at ~/.av/config.yaml
With that, now to merge a partial or full stack, just queue the top most PR of the stack that you would like to merge:
After this, Aviator will automatically validate the changes in the stack, and merge all the changes to the target branch (typically main or master). At any time, you can also review the state of your PR using av pr status
.
Aviator also publishes man pages, that you can read for more details on the commands:
In addition, all commands also provide in-line help:
This is just a quick preview of things you can do with the Aviator CLI. Check our our how to guides for more specific use cases:
\