Skip to content

Allow gh stack add to initialize a stack when current branch is not part of a stack #275

Description

@skarim

Summary

When running gh stack add from a regular branch that is not part of an existing stack, the command fails with:

✗ current branch "..." is not part of a stack
Checkout an existing stack using gh stack checkout or create a new stack using gh stack init

Proposal

Make gh stack add more ergonomic when invoked from a branch that is not yet part of a stack by allowing it to initialize a stack first and then add the level. Possible behaviors:

  • Interactive flow (recommended default): if the current branch is not part of a stack, prompt the user with a yes/no confirmation to run gh stack init first, then proceed with gh stack add.
    Example:
    $ gh stack add
    Current branch is not part of a stack. Initialize a new stack here and continue? (Y/n)
    
  • Explicit flag: provide a --init flag to run non-interactively (useful for scripts/CI): gh stack add --init would run gh stack init automatically then add the level.
  • Automatic (opt-in via config): an option in config to always auto-initialize when adding from a non-stack branch.

UX details

  • If prompting, the command should mirror existing gh conventions for confirmation prompts and be skippable with --yes/-y if desired.
  • When auto-initializing, preserve the same behavior and defaults as gh stack init (stack name, base branch selection, etc.).

Rationale

This reduces friction for users who create a branch and decide they want to start a stack on it (e.g., to add a stack level) without having to remember to run gh stack init first. The current failure is surprising and requires an extra manual step; a small interactive prompt or a --init flag would make the flow smoother.

Implementation notes / edge cases

  • Ensure behavior is consistent with scripts and non-interactive environments (honor --init, --yes, and standard CI detection).
  • Preserve backwards compatibility: by default prompt the user rather than silently creating a stack unless the user explicitly requests automatic behavior.

Conversation context

This suggestion came from a user in Slack requesting gh stack add to either automatically run gh stack init or ask for confirmation when the current branch is not part of a stack.

View original Slack conversation

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions