Summary
Allow gh stack checkout (no arguments) to detect whether the current local branch belongs to a stack, confirm with the user, and then checkout that stack locally.
Background
When working in a fresh Codespace (or any environment) developers often git checkout their feature branch but forget to check out the corresponding stack. Running gh stack add currently emits a message like:
✗ current branch "overview-comments/new-view-controls" is not part of a stack
Checkout an existing stack using gh stack checkout or create a new stack using gh stack init
This makes me expect that running gh stack checkout (without args) might look up the stack for the current branch. It would be convenient if the command did that automatically.
User story / expected behavior
- When the user runs
gh stack checkout with no arguments, the CLI should call the list stacks API and determine whether the current local branch is part of a stack.
- If the current branch is part of exactly one stack:
- Show a confirmation message mentioning the stack (and branch), e.g.:
"Found stack STACK_NAME that includes branch BRANCH_NAME. Checkout stack STACK_NAME? [Y/n]"
- If the user confirms, proceed with checking out the stack locally (same behavior as
gh stack checkout STACK_NAME).
- If the user declines, abort without changes.
- If the current branch is not part of any stack, preserve existing behavior (print the current helpful guidance suggesting
gh stack checkout <stack> or gh stack init).
- If the current branch appears in multiple stacks (edge case): present a numbered list of matching stacks and prompt the user to pick one (or cancel).
Acceptance criteria
gh stack checkout without args queries the list stacks API and inspects stack membership for the current git branch.
- The command only proceeds automatically after explicit user confirmation.
- If no matching stack is found, the command returns the same guidance/error message as today.
- The user-facing messages are clear and match CLI UX conventions used in other
gh commands.
Implementation notes / considerations
- Use the same API that powers listing stacks to determine which stack(s) include the branch name.
- Ensure the CLI handles remote vs local branch naming differences (e.g.
origin/branch vs branch) consistently.
- Consider non-interactive/CI usage: support a
--yes/-y flag to auto-confirm when callers expect non-interactive behavior.
- If there are multiple matching stacks, prefer presenting an interactive choice; in non-interactive mode, fail with a clear error and exit code.
Tag
checkout-auto-detect-stack
View original Slack conversation
Summary
Allow
gh stack checkout(no arguments) to detect whether the current local branch belongs to a stack, confirm with the user, and then checkout that stack locally.Background
When working in a fresh Codespace (or any environment) developers often
git checkouttheir feature branch but forget to check out the corresponding stack. Runninggh stack addcurrently emits a message like:✗ current branch "overview-comments/new-view-controls" is not part of a stack
Checkout an existing stack using
gh stack checkoutor create a new stack usinggh stack initThis makes me expect that running
gh stack checkout(without args) might look up the stack for the current branch. It would be convenient if the command did that automatically.User story / expected behavior
gh stack checkoutwith no arguments, the CLI should call the list stacks API and determine whether the current local branch is part of a stack."Found stack
STACK_NAMEthat includes branchBRANCH_NAME. Checkout stackSTACK_NAME? [Y/n]"gh stack checkout STACK_NAME).gh stack checkout <stack>orgh stack init).Acceptance criteria
gh stack checkoutwithout args queries the list stacks API and inspects stack membership for the current git branch.ghcommands.Implementation notes / considerations
origin/branchvsbranch) consistently.--yes/-yflag to auto-confirm when callers expect non-interactive behavior.Tag
checkout-auto-detect-stack
View original Slack conversation