.agents/skills/gh-stack/references/commands.md
gh stack <command> --help is authoritative for flags and arguments. (gh stack help <command> only prints the top-level help.) This file only covers behavior --help does not
explain: preconditions, side effects, atomicity, and failure modes.
Creates the stack and checks out the last branch in the list, so a single init can lay down
the whole chain: gh stack init auth api frontend.
init processes branch arguments from bottom to top. Existing branches are adopted. If the first
branch does not exist, it is created from the trunk; each later new branch is created from the
branch immediately before it. There is no separate adopt mode — existence decides. --base
selects a non-default trunk.
init also enables git rerere. Under a TTY the first run in a repo asks for confirmation; set
git config rerere.enabled true beforehand to skip it.
can only add branches on top of the stack. Run gh stack top
first.-Am, add does not touch the working tree, so
staged and unstaged changes follow you onto the new branch. Commit or stash first for a clean start.add -Am commits in place when the current branch has no commits yet — for example
immediately after init — instead of creating a branch. This is deliberate: the first layer
usually needs its content before a second layer exists.-A and -u are mutually exclusive. Without -m, either opens an editor for the commit
message, so agents must always pair them with -m.Pushes every active (non-merged, non-queued) branch in one multi-ref push with per-branch
--force-with-lease.
Not atomic. Some branches may update while another is rejected. A rejection means that branch moved on the remote; fix that branch and rerun — rerunning is safe and skips what already landed.
push never creates or updates pull requests. Use submit for that.
Pushes each active branch, then creates a PR for every branch that lacks one, basing it on the first non-merged ancestor, then links them into a Stack on GitHub.
--force-with-lease. If a later
push is rejected, earlier pushes and PR updates stand. Fix the rejection and rerun the same command.submit forks the remaining unmerged branches into a new stack rooted at the trunk and creates
it on GitHub, leaving the merged stack untouched.--auto: a branch with a single commit uses that commit's subject as
the title and its body as the PR body. A branch with multiple commits humanizes the branch name
(hyphens and underscores become spaces). There is no flag for a custom title or body; use
gh pr edit afterwards.--open marks new and existing PRs ready for review; without it new PRs are drafts.submit exits 9 when
non-interactive (under a TTY it offers to create ordinary unstacked PRs instead).Creates or updates a stack on GitHub without any local tracking state. This is the path for
branches managed by another tool or living in another worktree — see troubleshooting.md.
gh stack link 7 feature-c. Arguments already in the stack are
skipped; arguments belonging to a different stack are rejected.link never removes a PR from a stack.The routine command. Steps, in order:
troubleshooting.md).sync never opens PRs; that is submit.--prune is passed in a non-interactive
environment.Pulls from the remote and cascade-rebases. Use it when sync reported a conflict or when you need
to rebase only part of the stack.
--upstack rebases from the current branch to the top. This is what you run after editing a
lower layer.--downstack rebases from the trunk to the current branch.--no-trunk skips fetching and the trunk rebase entirely, aligning stack branches with each
other only.--continue after staging resolutions; --abort restores every branch.--onto against the correct target, so a
squash-merged parent does not produce spurious conflicts.--json writes the machine-readable payload to stdout. Its schema is in SKILL.md.view opens a full-screen TUI when stdout is a TTY, and prints static text when piped.--short prints a compact one-line-per-branch summary and never opens the TUI, but it is
formatted for humans; parse --json instead.view refreshes PR state from GitHub as a side effect, best-effort — it does not fail when the
API is unreachable.Accepts a stack number, PR number, PR URL, or branch name.
checkout
cannot be forced past it. Run gh stack unstack --local first, then retry.checkout has no flags. It relies on remote.pushDefault when several remotes exist.Removes the stack grouping only. It never deletes pull requests or branches.
--local removes local tracking only and never contacts GitHub. Combining --local with a stack
number that is not tracked locally is an error.--squash, --rebase, --merge, or --merge-method <method>. Without
one, the last-used method is reused.gh pr merge cannot merge a stack. Always use gh stack merge.up, down, top, bottom, and trunk are always non-interactive. up and down accept a
count (gh stack up 3). Movement clamps at the stack bounds, and merged branches are skipped when
navigating from an active branch, so bottom lands on the lowest unmerged branch.
gh stack switch is a selection menu with no non-interactive path. Use the commands above instead.