Skip to content

Commit 1e3b9ee

Browse files
committed
updated skill instructions
1 parent 97e3fea commit 1e3b9ee

1 file changed

Lines changed: 37 additions & 28 deletions

File tree

skills/gh-stack/SKILL.md

Lines changed: 37 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -41,18 +41,35 @@ The GitHub CLI (`gh`) v2.0+ must be installed and authenticated. Install the ext
4141
gh extension install github/gh-stack
4242
```
4343

44+
Before using `gh stack`, configure git to prevent interactive prompts:
45+
46+
```bash
47+
git config rerere.enabled true # remember conflict resolutions (skips prompt on init)
48+
git config remote.pushDefault origin # if multiple remotes exist (skips remote picker)
49+
```
50+
4451
## Agent rules
4552

46-
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.
4756
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.
5160
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.
5261
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`.
5362
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.
5463
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.
5564

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+
5673
## Thinking about stack structure
5774

5875
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.
@@ -378,10 +395,10 @@ gh stack init --base main --adopt new-branch-1 new-branch-2 new-branch-3
378395

379396
### Initialize a stack — `gh stack init`
380397

381-
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.
382399

383400
```
384-
gh stack init [flags] [branches...]
401+
gh stack init [flags] <branches...>
385402
```
386403

387404
```bash
@@ -415,16 +432,16 @@ gh stack init --adopt branch-a branch-b branch-c
415432
- Creates any branches that don't already exist (branching from the trunk branch)
416433
- In `--adopt` mode: validates all branches exist, rejects if any is already in a stack or has an existing PR
417434
- 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
419436

420437
---
421438

422439
### Add a branch — `gh stack add`
423440

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.
425442

426443
```
427-
gh stack add [flags] [branch]
444+
gh stack add [flags] <branch>
428445
```
429446

430447
**Recommended workflow — create the branch, then use standard git:**
@@ -501,14 +518,10 @@ gh stack push --remote upstream
501518

502519
### Submit branches and create PRs — `gh stack submit`
503520

504-
Push all stack branches and create PRs on GitHub.
505-
506-
```
507-
gh stack submit [flags]
508-
```
521+
Push all stack branches and create PRs on GitHub. **Always pass `--auto`** — without it, `submit` prompts for a PR title for each new branch.
509522

510523
```bash
511-
# Submit and auto-title new PRs
524+
# Submit and auto-title new PRs (required for non-interactive use)
512525
gh stack submit --auto
513526

514527
# Submit and create PRs as drafts
@@ -517,7 +530,7 @@ gh stack submit --auto --draft
517530

518531
| Flag | Description |
519532
|------|-------------|
520-
| `--auto` | Auto-generate PR titles without prompting |
533+
| `--auto` | Auto-generate PR titles without prompting (**required** for non-interactive use) |
521534
| `--draft` | Create new PRs as drafts |
522535
| `--remote <name>` | Remote to push to (use if multiple remotes exist) |
523536

@@ -620,20 +633,16 @@ gh stack rebase --abort
620633

621634
### View the stack — `gh stack view`
622635

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.
628637

629638
```bash
630-
# Structured JSON output (recommended)
639+
# Always use --json
631640
gh stack view --json
632641
```
633642

634643
| Flag | Description |
635644
|------|-------------|
636-
| `--json` | Output stack data as JSON to stdout |
645+
| `--json` | Output stack data as JSON to stdout (**required** for non-interactive use) |
637646

638647
**`--json` output format:**
639648

@@ -682,8 +691,6 @@ Fields per branch:
682691
- `needsRebase` — whether the base branch is not an ancestor (non-linear history)
683692
- `pr` — PR metadata (omitted if no PR exists). `state` is `"OPEN"` or `"MERGED"`.
684693

685-
> **Note:** `--short` outputs a compact text view with box-drawing characters and status icons. Prefer `--json` for programmatic use.
686-
687694
---
688695

689696
### Navigate the stack
@@ -705,7 +712,7 @@ Navigation clamps to stack bounds. Merged branches are skipped when navigating f
705712

706713
### Check out a stack — `gh stack checkout`
707714

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.
709716

710717
```
711718
gh stack checkout <pr-number | branch>
@@ -719,9 +726,11 @@ gh stack checkout 42
719726
gh stack checkout feature-auth
720727
```
721728

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>`.
723732
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.
725734

726735
---
727736

0 commit comments

Comments
 (0)