Introduction
Thegt
CLI tool has 2 key purposes:
- Simplifying git commands, especially some of the sharper edges like rebasing.
- Enabling PR stacking, which can help you move faster and stay unblocked.
git
and pull request creation is compelling on its own! However, adding pull request stacking to your workflow levels it up even further.
To read about the benefits of pull request stacking, visit stacking.dev.
The workflow
This guide will walk you through the lifecycle of stacking: creating stacks, responding to reviewer feedback up and down the stack, pulling in new changes from the main branch to open stacks, and finally merging. Not all changes require stacks, but the same commands & concepts apply to a single PR as to a stack of 25 PRs. The Graphite workflow can be broken down to the following steps:1
Create a stack
2
Submit the stack
3
Address feedback
4
Merge the stack
5
Sync from trunk & clean up your merged branches locally
Creating a first pull request
Creating a pull request withgt
should feel similar to workflows you already do with GitHub:
Terminal
Stacking a second pull request
While you’re waiting for a review on your first pull request, you can continue to build out changes by stacking a second pull request on top of the first. A stack is a sequence of pull requests, each building off of its parent. Stacks enable users to break up a large engineering task into a series of small, incremental code changes, each of which can be tested, reviewed, and merged independently. If you aren’t sure how to start breaking up your changes into stacks of PRs, check out our more detailed guide with 5 helpful frameworks for structuring a stack.gt
treats stacking as a first-class concept. Stacking new PRs, addressing reviewer feedback in any part of your stack, and making sure upstack branches stay in sync with changes downstack are all seamlessly handled for you by the core gt
commands.
To stack more changes on top of an existing pull request:
Terminal
Terminal
Terminal
Terminal
TipYou can repeat the process of checking out the top branch, making changes, and creating a new branch with
gt create
to create larger and larger PR stacks.Addressing reviewer feedback
It’s likely that you’ll be asked to make some changes to your stack as a result of code review. Thegt modify
command will let you edit any branch in a stack, and automatically restack all the branches above it.
Example: You have a stack of 2 PRs, and your coworker asks you to make changes on the bottom-most PR.
First, checkout the bottom PR and address the changes in your editor:
Terminal
gt modify
to amend the last commit in this branch and restack all the branches above it:
Terminal
Terminal
gt modify
as well. Replace the gt modify -a
command with:
Terminal
Pulling the latest changes from main into your stack
As you’re developing new features, themain
trunk branch will eventually get ahead of your open branches.
To update all of your open stacks with the latest changes from main
, run:
Terminal
- Pull the latest changes into main
- Restack (rebase) all your open PRs on top of the new changes in main
- Prompt you to delete any local merged/closed branches
gt restack
to fix any conflicts.
Merging your stack
Once your stack has been reviewed and is passing CI, open the top of the stack in the Graphite UI:Terminal
Sync from trunk & clean up your merged branches locally
Once you’ve merged your stack intomain
(or whatever your trunk branch is), run gt sync
to get the latest changes in main
. In addition to fetching updates, gt sync
will:
- Automatically detect any merged/closed branches and prompt you to delete them locally.
- Rebases any branches/stacks you have locally onto the newest changes.
TipTo make sure you’re always working on the most up-to-date version of your base branch, make sure you’re frequently running
gt sync
throughout your workflow.