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 your remote repository
If your remotetrunk
branch (also known as origin/main
) gets ahead of your local repository while youβre developing, you can use gt sync
to bring your stack up-to-date. Using a trunk-based-development workflow allows you to frequently sync changes from your main
branch without running into unmanageable merge conflicts.
gt sync
does a few things:
-
Pulls in the latest changes from
main
- Prompts you to delete any stale local branches which have been merged into trunk
-
Restacks your upstack branches which have not been merged and your current stack onto
main
. If you encounter any merge conflicts, youβll be prompted to resolve them.
pp--06-14-part_1
, of a three-branch stack. Since you know that your main
branch has been updated with the changes of pp--06-14-part_1,
you can sync that change from remote using the gt sync
command:
Terminal
gt log
, you see that part_2
is now based on main
:
Terminal
Dealing with conflicts
Syncing from a remote repository is almost always followed by restacking any of the dependent branches.gt sync
tries to restack as much as it can without needing your input to resolve conflicts.
You can think of restacking branches as distributing the new changes from your main
branch across all of the branches that are dependent on trunk and havenβt yet been merged.
If these changes conflict with changes youβve made, gt sync
might output something like:
Terminal
09-14-part_4
and run gt restack
, which will take into standard git
conflict resolution (just like if you had hit conflicts during gt modify
).