You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
1.**Always supply branch names as positional arguments** to `init`, `add`, and `checkout`.
53
+
**All `gh stack` commands must be run non-interactively.** Every command invocation must include the flags and positional arguments needed to avoid prompts, TUIs, and interactive menus. If a command would prompt for input, it will hang indefinitely.
54
+
55
+
1.**Always supply branch names as positional arguments** to `init`, `add`, and `checkout`. Running these commands without arguments triggers interactive prompts.
47
56
2.**When a prefix is set, pass only the suffix to `add`.**`gh stack add auth` with prefix `feat` → `feat/auth`. Passing `feat/auth` creates `feat/feat/auth`.
48
-
3.**Always use `--auto`when pushing** to skip PR title prompts.
49
-
4.**Always use `--json`when viewing**to get structured output.
50
-
5.**Use `--remote <name>` when multiple remotes are configured**, or set `remote.pushDefault` in git config.
57
+
3.**Always use `--auto`with `gh stack submit`** to auto-generate PR titles. Without `--auto`, `submit`prompts for a title for each new PR.
58
+
4.**Always use `--json`with `gh stack view`.**Without `--json`, the command launches an interactive TUI that cannot be operated by agents. There is no other appropriate flag — always pass `--json`.
59
+
5.**Use `--remote <name>` when multiple remotes are configured**, or pre-configure `git config remote.pushDefault origin`. Without this, `push`, `submit`, `sync`, and `checkout` trigger an interactive remote picker.
51
60
6.**Avoid branches shared across multiple stacks.** If a branch belongs to multiple stacks, commands exit with code 6. Check out a non-shared branch first.
52
61
7.**Plan your stack layers by dependency order before writing code.** Foundational changes (models, APIs, shared utilities) go in lower branches; dependent changes (UI, consumers) go in higher branches. Think through the dependency chain before running `gh stack init`.
53
62
8.**Use standard `git add` and `git commit` for staging and committing.** This gives you full control over which changes go into each branch. The `-Am` shortcut is available but should not be the default approach—stacked PRs are most effective when each branch contains a deliberate, logical set of changes.
54
63
9.**Navigate down the stack when you need to change a lower layer.** If you're working on a frontend branch and realize you need API changes, don't hack around it at the current layer. Navigate to the appropriate branch (`gh stack down`, `gh stack checkout`, or `gh stack bottom`), make and commit the changes there, run `gh stack rebase --upstack`, then navigate back up to continue.
55
64
65
+
**Never do any of the following — each triggers an interactive prompt or TUI that will hang:**
66
+
- ❌ `gh stack view` or `gh stack view --short` — always use `gh stack view --json`
67
+
- ❌ `gh stack submit` without `--auto` — always use `gh stack submit --auto`
68
+
- ❌ `gh stack init` without branch arguments — always provide branch names
69
+
- ❌ `gh stack add` without a branch name — always provide a branch name
70
+
- ❌ `gh stack checkout` without an argument — always provide a PR number or branch name
71
+
- ❌ `gh stack checkout <pr-number>` when a different local stack already exists on those branches — this triggers an unbypassable conflict resolution prompt; use `gh stack unstack` first to remove the local stack, then retry the checkout
72
+
56
73
## Thinking about stack structure
57
74
58
75
Each branch in a stack should represent a **discrete, logical unit of work** that can be reviewed independently. The changes within a branch should be cohesive—they belong together and make sense as a single PR.
Creates a new stack. Provide branch names as positional arguments.
398
+
Creates a new stack. **Always provide at least one branch name as a positional argument** — running without branch arguments triggers interactive prompts that agents cannot use.
- Creates any branches that don't already exist (branching from the trunk branch)
416
433
- In `--adopt` mode: validates all branches exist, rejects if any is already in a stack or has an existing PR
417
434
- Checks out the last branch in the list
418
-
- Enables `git rerere` so conflict resolutions are remembered across rebases
435
+
- Enables `git rerere` so conflict resolutions are remembered across rebases. On first run in a repo, this may trigger a confirmation prompt — pre-configure with `git config rerere.enabled true` to avoid it
419
436
420
437
---
421
438
422
439
### Add a branch — `gh stack add`
423
440
424
-
Add a new branch on top of the current stack. Must be run while on the topmost branch (or the trunk if the stack has no branches yet). Always provide an explicit branch name.
441
+
Add a new branch on top of the current stack. Must be run while on the topmost branch (or the trunk if the stack has no branches yet). **Always provide a branch name** — running without one triggers an interactive prompt.
425
442
426
443
```
427
-
gh stack add [flags] [branch]
444
+
gh stack add [flags] <branch>
428
445
```
429
446
430
447
**Recommended workflow — create the branch, then use standard git:**
|`--auto`| Auto-generate PR titles without prompting |
533
+
|`--auto`| Auto-generate PR titles without prompting (**required** for non-interactive use) |
521
534
|`--draft`| Create new PRs as drafts |
522
535
|`--remote <name>`| Remote to push to (use if multiple remotes exist) |
523
536
@@ -620,20 +633,16 @@ gh stack rebase --abort
620
633
621
634
### View the stack — `gh stack view`
622
635
623
-
Display the current stack's branches, PR status, and recent commits. Use `--json` for structured output.
624
-
625
-
```
626
-
gh stack view [flags]
627
-
```
636
+
Display the current stack's branches, PR status, and recent commits. **Always pass `--json`** — without it, this command launches an interactive TUI that agents cannot operate.
628
637
629
638
```bash
630
-
#Structured JSON output (recommended)
639
+
#Always use --json
631
640
gh stack view --json
632
641
```
633
642
634
643
| Flag | Description |
635
644
|------|-------------|
636
-
|`--json`| Output stack data as JSON to stdout |
645
+
|`--json`| Output stack data as JSON to stdout (**required** for non-interactive use) |
637
646
638
647
**`--json` output format:**
639
648
@@ -682,8 +691,6 @@ Fields per branch:
682
691
-`needsRebase` — whether the base branch is not an ancestor (non-linear history)
683
692
-`pr` — PR metadata (omitted if no PR exists). `state` is `"OPEN"` or `"MERGED"`.
684
693
685
-
> **Note:**`--short` outputs a compact text view with box-drawing characters and status icons. Prefer `--json` for programmatic use.
686
-
687
694
---
688
695
689
696
### Navigate the stack
@@ -705,7 +712,7 @@ Navigation clamps to stack bounds. Merged branches are skipped when navigating f
705
712
706
713
### Check out a stack — `gh stack checkout`
707
714
708
-
Check out a stack from a pull request number or branch name.
715
+
Check out a stack from a pull request number or branch name.**Always provide an argument** — running `gh stack checkout` without arguments triggers an interactive selection menu.
709
716
710
717
```
711
718
gh stack checkout <pr-number | branch>
@@ -719,9 +726,11 @@ gh stack checkout 42
719
726
gh stack checkout feature-auth
720
727
```
721
728
722
-
When a PR number is provided (e.g. `123`), the command fetches the stack on GitHub, pulls the branches, and sets up the stack locally. If the stack already exists locally and matches, it switches to the branch. If the local and remote stacks have different compositions, you'll be prompted to resolve the conflict by deciding whether to replace the local stack with the remote version or delete the remote stack and keep the local version.
729
+
When a PR number is provided (e.g. `123`), the command fetches the stack on GitHub, pulls the branches, and sets up the stack locally. If the stack already exists locally and matches, it switches to the branch.
730
+
731
+
> **⚠️ Agent warning:** If the local and remote stacks have different branch compositions, this command triggers an interactive conflict-resolution prompt that cannot be bypassed with a flag. To avoid this: run `gh stack unstack` first to remove the conflicting local stack, then retry `gh stack checkout <pr-number>`.
723
732
724
-
When a branch name is provided, the command resolves it against locally tracked stacks only.
733
+
When a branch name is provided, the command resolves it against locally tracked stacks only. This is always safe for non-interactive use.
0 commit comments