Restack branches
Learn to restack Git branches efficiently with Graphite's CLI.

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:

Terminal
> gt log long
* ff393d3 - (40 minutes ago) part 1 (#100) - Pranathi Peri (origin/main, origin/HEAD, main)
| * 7ebfd3f - (14 hours ago) part 3 - Pranathi Peri (origin/pp--06-14-part_3, pp--06-14-part_3)
| * 6fe5a7c - (14 hours ago) part 2 - Pranathi Peri (HEAD -> pp--06-14-part_2, origin/pp--06-14-part_2)
| * 4f3f756 - (14 hours ago) part 1 - Pranathi Peri
|/

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.

Terminal
Hit conflict restacking pp--06-14-part_2 on main.
You are here (resolving pp--06-14-part_2):
◯ pp--06-14-part_3
◉ pp--06-14-part_2
◯ main
To fix and continue your previous Graphite command:
(1) resolve the listed merge conflicts
(2) mark them as resolved with gt add .
(3) run gt continue to continue executing your previous Graphite command
It's safe to cancel the ongoing rebase with `gt rebase --abort`

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:

Terminal
> gt continue -a
Resolved rebase conflict for pp--06-14-part_2.
Restacked pp--06-14-part_3 on pp--06-14-part_2.
> gt log short
◯ pp--06-14-part_3
◉ pp--06-14-part_2
◯ main
> gt log long
* 543c8b3 - (14 hours ago) part 3 - Pranathi Peri (pp--06-14-part_3)
* 778006d - (14 hours ago) part 2 - Pranathi Peri (HEAD -> pp--06-14-part_2)
* ff393d3 - (44 minutes ago) part 1 (#100) - Pranathi Peri (origin/main, origin/HEAD, main)

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.

On this page
Git inspired
Graphite's CLI and VS Code extension make working with Git effortless.
Learn more

Graphite
Git stacked on GitHub

Stacked pull requests are easier to read, easier to write, and easier to manage.
Teams that stack ship better software, faster.

Or install our CLI.
Product Screenshot 1
Product Screenshot 2