-
Using
gt checkout
to hop between branches in your stack -
Adding changes to a branch using
gt modify
-
Pushing the new changes to remote using
gt submit
Prerequisites
You should be familiar with how to:Working with commits
Any branch you create with Graphite (using the recommended workflow) will already contain a commit with your initial changes. There are two main ways to update your branch with new changes:-
Maintain the 1:1 relationship between commits and branches, meaning you’ll use
gt modify
to continuously amend the commit on the branch (recommended) -
Create multiple commits on each branch using
gt modify --commit
each time you make changes
Amend commits
By default, thegt modify
command amends the commit on the branch. Here’s how you would address feedback on a branch in the middle of your stack by amending a commit:
Terminal
Create commits
If you prefer to create an entirely new commit for each of the changes you make to a branch, you can usegt modify
with the --commit
flag:
Terminal
Automatically restack branches
Given that there are no merge conflicts (see next section),gt modify
will automatically restack any upstack branches on top of your new changes and provide the following output:
Terminal
Resolve upstack conflicts when modifying branches
Ifgt modify
encounters any conflicts as they recursively restack your branches, you’ll be prompted to resolve your conflicts before continuing:
Terminal
gt abort
.
Read more about restacking branches.
Absorbing changes into your stack
Whilegt modify
allows you to make changes to a single branch in your stack, Graphite also provides gt absorb
, which automatically applies your changes to the relevant branches throughout your stack, without needing to check each one out individually.
Each change will be amended into the correct commit in a branch downstack from the currently checked out branch, inclusive.
Before applying the changes, gt absorb
will show which lines will be absorbed into each commit, and prompt for confirmation (unless the --force
flag is passed).
Terminal
How does gt absorb
work?
For each “hunk” of changed lines, gt absorb
attempts to “commute” the change with each commit in your stack to find the most recent commit that they do not commute with, which tends to be the correct commit to amend them to. It is possible that a hunk commutes all the way down to your trunk branch, in which case it will not be absorbed into any commit. In this case, you can then apply those changes to the correct branch manually with gt checkout
and gt modify
.