Sync changes from a remote repository
Learn how to sync changes from a remote repository with Graphite's CLI, managing branch updates and conflicts.

You should be familiar with how to:

If your remote trunk 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.

Let's say that you've squash-and-merged in the first branch in your stack, 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 sync
๐ŸŒฒ Pulling main from remote...
main fast-forwarded to 4604ea03f728126332fa23bbfa74643c18d2fca3.
๐Ÿงน Checking if any branches have been merged/closed and can be deleted...
โœ” pp--06-14-part_1 is merged into main. Delete it? โ€ฆ yes
Deleted branch pp--06-14-part_1
Restacked pp--06-14-part_2 on main.
Restacked pp--06-14-part_3 on pp--06-14-part_2.

If you run gt log, you see that part_2 is now based on main:

Terminal
โ—‰ pp--06-14-part_3 (current)
โ”‚ 39 minutes ago
โ”‚
โ”‚ PR #101 part 3
โ”‚ pp--06-14-part_3: https://app.graphite.dev/github/pr/withgraphie/pranathi-test-repo/102
โ”‚
โ”‚ 95338df - part 3
โ”‚
โ—ฏ pp--06-14-part_2
โ”‚ 39 minutes ago
โ”‚
โ”‚ PR #101 part 2
โ”‚ pp--06-14-part_2: https://app.graphite.dev/github/pr/withgraphite/pranathi-test-repo/101
โ”‚
โ”‚ 95610c6 - part 2
โ”‚
โ—ฏ main (current)
โ”‚ 30 minutes ago
โ”‚

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
All branches restacked cleanly, except for:
โ–ธ 09-14-part_4
You can fix these conflicts with gt restack.

This means you need to check out 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).

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