Skip to main content

Prerequisites

You should be familiar with how to:

Edit the order of branches in your stack

The Graphite CLI allows you to modify the dependencies of any of your branches often with just a single command.

gt move to modify branch ordering

gt move rebases the current branch and all of its recursive children (anything upstack of the current branch) onto a branch of your choice.
Terminal
Output of the previous commands:
Terminal
You can also run gt move --onto <BRANCH_NAME> if you already know the branch name of your current branch’s new parent. After successfully running gt move --onto with main, you should see the following output (given that there are no merge conflicts)
Terminal

gt reorder to modify branch ordering

If you’ve created a stack of several branches and want to open an editor to do an interactive re-ordering of branches, you can use gt reorder. gt reorder opens an editor that allows you to manually copy and paste branch names into different orders. The editor will only show the branch you currently have checked out, as well as anything downstack (ancestors) of it.
Terminal
Output of the previous commands (in a vim editor):
Terminal
You can shuffle, add, and delete branches as necessary to produce a stack that has the dependencies you desire. For example, deleting second_branch in the above example yields the following output:
Terminal

—insert flag on create to modify branch ordering

To create an entirely new branch in the middle of a stack and automatically rebase any dependent branches, use the optional --insert branch when invoking the gt create command. See the following example:
Terminal
Output of the previous commands:
Terminal

Resolve merge conflicts when editing branch ordering

Under the hood, gt move , gt reorder, and gt create --insert perform restacks just like gt modify —and there is a chance you can run into merge conflicts when invoking them. If you do, you can follow the same flow as encountering merge conflicts after creating/amending commits to branches mid-stack.