Skip to content

Commit b381144

Browse files
committed
clearer prefix instructions
1 parent 4e0263f commit b381144

1 file changed

Lines changed: 38 additions & 28 deletions

File tree

skills/gh-stack/SKILL.md

Lines changed: 38 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ metadata:
1616

1717
```
1818
main (trunk)
19-
└── auth-layer → PR #1 (base: main) - bottom (closest to trunk)
20-
└── api-endpoints → PR #2 (base: auth-layer)
21-
└── frontend → PR #3 (base: api-endpoints) - top (furthest from trunk)
19+
└── feat/auth-layer → PR #1 (base: main) - bottom (closest to trunk)
20+
└── feat/api-endpoints → PR #2 (base: feat/auth-layer)
21+
└── feat/frontend → PR #3 (base: feat/api-endpoints) - top (furthest from trunk)
2222
```
2323

2424
The **bottom** of the stack is the branch closest to the trunk, and the **top** is the branch furthest from the trunk. Each branch inherits from the one below it. Navigation commands (`up`, `down`, `top`, `bottom`) follow this model: `up` moves away from trunk, `down` moves toward it.
@@ -44,13 +44,14 @@ gh extension install github/gh-stack
4444
## Agent rules
4545

4646
1. **Always supply branch names as positional arguments** to `init`, `add`, and `checkout`.
47-
2. **Always use `--auto` when pushing** to skip PR title prompts.
48-
3. **Always use `--json` when viewing** to get structured output.
49-
4. **Use `--remote <name>` when multiple remotes are configured**, or set `remote.pushDefault` in git config.
50-
5. **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.
51-
6. **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`.
52-
7. **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.
53-
8. **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.
47+
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.
51+
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+
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+
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+
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.
5455

5556
## Thinking about stack structure
5657

@@ -64,14 +65,18 @@ Stacked branches form a dependency chain: each branch builds on the one below it
6465

6566
```
6667
main (trunk)
67-
└── data-models ← shared types, database schema
68-
└── api-endpoints ← API routes that use the models
69-
└── frontend-ui ← UI components that call the APIs
70-
└── integration ← tests that exercise the full stack
68+
└── feat/data-models ← shared types, database schema
69+
└── feat/api-endpoints ← API routes that use the models
70+
└── feat/frontend-ui ← UI components that call the APIs
71+
└── feat/integration ← tests that exercise the full stack
7172
```
7273

7374
This is illustrative — choose branch names and layer boundaries that reflect the specific work you're doing. The key principle is: if code in one layer depends on code in another, the dependency must be in the same branch or a lower one.
7475

76+
### Branch naming
77+
78+
Prefer initializing stacks with a prefix (`-p`). Prefixes group branches under a namespace (e.g., `feat/auth`, `feat/api`) and keep branch names clean and consistent. When a prefix is set, pass only the suffix to subsequent `add` calls — the prefix is applied automatically. Without a prefix, you'll need to pass the full branch name each time.
79+
7580
### Staging changes deliberately
7681

7782
Don't dump all changes into a single commit or branch. Stage changes in batches based on logical grouping:
@@ -111,12 +116,12 @@ Small, incidental fixes (e.g., fixing a typo you noticed) can go in the current
111116

112117
| Task | Command |
113118
|------|---------|
114-
| Create a stack | `gh stack init branch-a` |
115-
| Create a stack with a prefix | `gh stack init -p feat auth` |
119+
| Create a stack (recommended) | `gh stack init -p feat auth` |
120+
| Create a stack without prefix | `gh stack init auth` |
116121
| Adopt existing branches | `gh stack init --adopt branch-a branch-b` |
117122
| Set custom trunk | `gh stack init --base develop branch-a` |
118-
| Add a branch to stack | `gh stack add branch-name` |
119-
| Add branch + stage all + commit (shortcut) | `gh stack add -Am "message" new-branch` |
123+
| Add a branch to stack (suffix only if prefix set) | `gh stack add api-routes` |
124+
| Add branch + stage all + commit | `gh stack add -Am "message" api-routes` |
120125
| Push + create PRs | `gh stack push --auto` |
121126
| Push as drafts | `gh stack push --auto --draft` |
122127
| Push without creating PRs | `gh stack push --skip-prs` |
@@ -174,7 +179,7 @@ git commit -m "Add auth middleware tests"
174179

175180
# 4. When you're ready for a new concern, add the next branch
176181
gh stack add api-routes
177-
# → creates feat/api-routes (prefixed), checks it out
182+
# → creates feat/api-routes (prefix applied automatically — just pass the suffix)
178183

179184
# 5. Write code for the API layer
180185
cat > api.go << 'EOF'
@@ -189,7 +194,7 @@ git commit -m "Add API routes"
189194

190195
# 6. Add a third layer for frontend
191196
gh stack add frontend
192-
# → creates feat/frontend, checks it out
197+
# → creates feat/frontend (just the suffix — prefix is automatic)
193198

194199
cat > frontend.go << 'EOF'
195200
package frontend
@@ -366,28 +371,33 @@ gh stack init [branches...] [flags]
366371
```
367372

368373
```bash
369-
# Create a stack with new branches (branched from trunk)
374+
# Set a branch prefix (recommended — subsequent `add` calls only need the suffix)
375+
gh stack init -p feat auth
376+
# → creates feat/auth
377+
378+
# Multi-part prefix (slashes are fine — suffix-only rule still applies)
379+
gh stack init -p monalisa/billing auth
380+
# → creates monalisa/billing/auth
381+
382+
# Create a stack with new branches (no prefix — use full branch names)
370383
gh stack init branch-a branch-b branch-c
371384

372385
# Use a different trunk branch
373386
gh stack init --base develop branch-a branch-b
374387

375388
# Adopt existing branches into a stack
376389
gh stack init --adopt branch-a branch-b branch-c
377-
378-
# Set a branch prefix (branch names you provide are automatically prefixed)
379-
gh stack init -p feat auth
380-
# → creates feat/auth
381390
```
382391

383392
| Flag | Description |
384393
|------|-------------|
385394
| `-b, --base <branch>` | Trunk branch (defaults to the repo's default branch) |
386395
| `-a, --adopt` | Adopt existing branches instead of creating new ones |
387-
| `-p, --prefix <string>` | Set a branch name prefix for auto-generated names |
396+
| `-p, --prefix <string>` | Branch name prefix. Subsequent `add` calls only need the suffix (e.g., with `-p feat`, `gh stack add auth` creates `feat/auth`) |
388397

389398
**Behavior:**
390399

400+
- Using `-p` is recommended — it simplifies branch naming for subsequent `add` calls
391401
- Creates any branches that don't already exist (branching from the trunk branch)
392402
- In `--adopt` mode: validates all branches exist, rejects if any is already in a stack or has an existing PR
393403
- Checks out the last branch in the list
@@ -406,7 +416,7 @@ gh stack add [branch] [flags]
406416
**Recommended workflow — create the branch, then use standard git:**
407417

408418
```bash
409-
# Create a new branch and switch to it
419+
# Create a new branch and switch to it (just the suffix — prefix is applied automatically)
410420
gh stack add api-routes
411421

412422
# Write code, stage deliberately, and commit
@@ -438,7 +448,7 @@ gh stack add -um "Fix auth bug" auth-fix
438448

439449
- `-A` and `-u` are mutually exclusive.
440450
- When the current branch has no commits (e.g., right after `init`), `add -Am` commits directly on the current branch instead of creating a new one.
441-
- If a prefix was set during `init`, the prefix is applied to branch names: `prefix/branch-name`.
451+
- **Prefix handling:** Only pass the suffix when a prefix is set. `gh stack add api` with prefix `todo``todo/api`. Passing `todo/api` creates `todo/todo/api`. Without a prefix, pass the full branch name.
442452
- If called from a branch that is not the topmost in the stack, exits with code 5: `"can only add branches on top of the stack"`. Use `gh stack top` to switch first.
443453
- **Uncommitted changes:** When using `gh stack add branch-name` without `-Am`, any uncommitted changes (staged or unstaged) in your working tree carry over to the new branch. This is standard git behavior — the working tree is not touched. Commit or stash changes on the current branch before running `add` if you want a clean starting point on the new branch.
444454

0 commit comments

Comments
 (0)