Syncing with a remote repository
Often, as you're building, the remote trunk branch will move ahead of your local repository, and you'll want to pull in the latest changes and resolve any conflicts before you land your pull requests.
Syncing your repo
If your remote trunk branch (i.e. origin/main
) gets ahead of your local repository while you're developing, you can use gt repo sync
to bring your stack up-to-date.
gt repo sync
does a few things:
Pulls in the latest changes from
origin/main
(or whatever your trunk branch is)Prompts you to delete any stale local branches which have been merged in (this works even if you use squash-and-merge)
Optionally restacks your up-stack 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 as part of the restack โ see the section on restacking for more details!
Let's say that we've squash-and-merged in one branch, pp--06-14-part_1
, of our three-branch stack from earlier. We can sync that change in from remote:
๐ฒ 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? โฆ yesDeleted branch pp--06-14-part_1
Now, if we run gt log
, we see that part_2
is now based on main
:
โ 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 (needs restack)โ 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โ
Since we didn't restack as part of the sync
command here (we could have done so with --restack
), we see that part_2
needs a restack onto main
. We'll talk about what that means in the next section: Restacking branches.