Prerequisites
You should be familiar with how to:- Create branches in a stack
- Visualize a stack
- Create and submit pull requests
- Update mid-stack branches
- Sync changes from a remote repository
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
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
Terminal
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.