Skip to content

Move around

Terminal window
# Move the checkout. No --apply: these change nothing but where you stand.
g2g up # the branch above
g2g down 2 # two below; from the bottom of a stack, down is the trunk
g2g top # follow the branch above until there is none
g2g bottom # the first branch above the trunk
g2g up --dry-run # say where, and the git switch that gets there, without moving

up, down, top and bottom move the checkout around a stack. They resolve the stack the way every stack command does, including --from (g2g, graphite or github) and --trunk where a Graphite ancestry declares more than one; see Where structure comes from.

These four are the one exception to preview-first, deliberately. Moving the checkout changes no ref, record or remote, and git switch already refuses to overwrite a local change, so a preview would only be a second command to type. --dry-run answers “where?” without moving: it prints the destination and the git switch that would reach it.

What they keep is everything else that makes the rest of g2g safe to run:

  • They never choose. At a fork they refuse and name the branches above, each as the git switch that would go there, because choosing between them is a guess.
  • They never recreate a branch. The switch is git switch --no-guess, so a branch a record names but this checkout lacks is refused rather than recreated from a remote.
  • They refuse mid-restack, because switching away strands the rebase in progress.

g2g up [n] switches to the branch directly above this one, or n branches up. A trunk is exactly where someone types up, yet no source describes a trunk as part of a stack, so from one it asks the g2g graph what is recorded directly on it: one branch is the answer, and more than one is a fork.

g2g down [n] switches to the branch directly below this one, or n branches down. From the bottom of a stack that is the trunk; from the trunk there is nothing below.

g2g top follows the branch above until there is none. Run from auth:

Switched to session · top of the stack from auth

At a fork it stops and names the branches above, as up does.

g2g bottom switches to the first branch above the trunk on the way down from this one.

With --json or --porcelain the destination is target, how it was reached is targetSource, the branches walked are listed, and the switch is command — the one that ran, or with --dry-run the one that would. command is absent when you are already there. See Output.