Restack Branches
Learn to restack Git branches efficiently with Graphite’s CLI.
Prerequisites
You should be familiar with how to:
A key benefit of using Graphite as opposed to vanilla git
when working with stacks is dependency management for your branches—keeping track of the “parent” of a given branch. When a parent branch changes in some way or is deleted, vanilla git
, because it does not have this concept of branch dependencies, leaves the parent as-is.
gt modify
automatically restacks any dependent branches and prompts you to resolve merge conflicts when needed. Another instance that requires branch restacking is after you’ve synced changes from a remote repository.
Here’s the output of gt log long
to get an idea of what’s happening on the git
level when gt sync
is unable to automatically restack:
main
has advanced to the squash-and-merge commit for part_1
, but part_2
—even though it is supposed to be based on main
now—is actually still sitting on the old version of part_1
.
gt restack
fixes that. This command, for the current stack, ensures that all branches are based on the current version of their parents.
Resolving merge conflicts during a restack is performed the same way as amending or creating a new commit on a branch in the middle of a stack:
After running the restack
command, you can see that git
and gt
are in agreement about the history. Next, you may want to resubmit the restacked versions of these branches (gt submit
), or make some changes to a branch mid-stack to address any review comments.