Skip to content

Commit 32de12d

Browse files
committed
update docs with link cmd details
1 parent 8f1f90a commit 32de12d

File tree

5 files changed

+153
-8
lines changed

5 files changed

+153
-8
lines changed

README.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,42 @@ gh stack submit --auto
307307
gh stack submit --draft
308308
```
309309

310+
### `gh stack link`
311+
312+
Link PRs into a stack on GitHub without local tracking.
313+
314+
```
315+
gh stack link [flags] <branch-or-pr> <branch-or-pr> [...]
316+
```
317+
318+
Creates or updates a stack on GitHub from branch names or PR numbers. This command does not store or modify any `gh stack` local tracking state. It is designed for users who manage branches with other tools locally (e.g., jj, Sapling, git-town) and want to simply open a stack of PRs.
319+
320+
Arguments are provided in stack order (bottom to top). Branch arguments are automatically pushed to the remote before creating or looking up PRs. For branches that already have open PRs, those PRs are used. For branches without PRs, new PRs are created automatically with the correct base branch chaining. Existing PRs whose base branch doesn't match the expected chain are corrected automatically.
321+
322+
If the PRs are not yet in a stack, a new stack is created. If some of the PRs are already in a stack, the existing stack is updated to include the new PRs. Existing PRs are never removed from a stack — the update is additive only.
323+
324+
| Flag | Description |
325+
|------|-------------|
326+
| `--base <branch>` | Base branch for the bottom of the stack (default: `main`) |
327+
| `--draft` | Create new PRs as drafts |
328+
| `--remote <name>` | Remote to push to (defaults to auto-detected remote) |
329+
330+
**Examples:**
331+
332+
```sh
333+
# Link branches into a stack (pushes branches, creates PRs, creates stack)
334+
gh stack link feature-auth feature-api feature-ui
335+
336+
# Link existing PRs by number
337+
gh stack link 10 20 30
338+
339+
# Add branches to an existing stack of PRs
340+
gh stack link 42 43 feature-auth feature-ui
341+
342+
# Use a different base branch and create PRs as drafts
343+
gh stack link --base develop --draft feat-a feat-b feat-c
344+
```
345+
310346
### `gh stack view`
311347

312348
View the current stack.

cmd/link.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ func LinkCmd(cfg *config.Config) *cobra.Command {
2626
Short: "Link PRs into a stack on GitHub without local tracking",
2727
Long: `Create or update a stack on GitHub from branch names or PR numbers.
2828
29-
This command works entirely via the GitHub API and does not modify
30-
any local state. It is designed for users who manage branches with
31-
external tools (e.g. jj) and want to use GitHub stacked PRs without
32-
adopting local stack tracking.
29+
This command does not rely on gh-stack local tracking state. It is
30+
designed for users who manage branches with external tools (e.g. jj)
31+
and want to use GitHub stacked PRs without adopting local stack
32+
tracking.
3333
3434
Arguments are provided in stack order (bottom to top). Each argument
3535
can be a branch name or a PR number. For numeric arguments, the

docs/src/content/docs/faq.md

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,11 +188,12 @@ No. Stacked PRs are built on standard git branches and regular pull requests. Yo
188188

189189
### Will this work with a different tool for stacking?
190190

191-
Yes, you can continue to use your tool of choice (e.g., jj, Sapling, ghstack, git-town, etc.) to manage stacks locally and push up your branches to GitHub.
191+
Yes, you can continue to use your tool of choice (e.g., jj, Sapling, git-town, etc.) to manage stacks locally and push up your branches to GitHub.
192192

193193
Stacked PRs on GitHub are based on the standard pull request model — any tool that creates PRs with the correct base branches can work with them. The `gh stack` CLI is purpose-built for the GitHub experience, but other tools that manage branch chains should be compatible.
194194

195-
You can also use the GitHub CLI in conjunction with other tools to open your PRs as a stack:
195+
You can also use the `gh stack link` command in conjunction with other tools to open your PRs as a stack:
196+
196197

197198
```bash
198199
# Create a stack of branches locally using jj
@@ -208,7 +209,30 @@ jj new -m "third change"
208209
jj bookmark create change3 --revision @
209210
# ...
210211

211-
# Use gh stack to submit a stack of PRs
212+
# Push branches and link them as a stack on GitHub
213+
# (creates PRs automatically if they don't exist)
214+
gh stack link change1 change2 change3
215+
```
216+
217+
This doesn't create any local tracking and only hits the APIs to create Stacked PRs.
218+
219+
If the provided branches already have open PRs, `link` will use them. If not, it creates PRs with the correct base branch chaining.
220+
221+
To add more to the stack, run `link` again, but be sure to include the full list of PRs/branches in the stack:
222+
223+
```bash
224+
gh stack link 123 124 125 change4 change5
225+
```
226+
227+
You can also use `--base` to specify a different trunk branch and `--draft` to create PRs as drafts:
228+
229+
```bash
230+
gh stack link --base develop --draft change1 change2 change3
231+
```
232+
233+
Alternatively, if you want full local stack tracking (for commands like `rebase`, `sync`, and navigation), you can adopt existing branches to local tracking with `gh stack`:
234+
235+
```bash
212236
gh stack init --adopt change1 change2 change3
213237
gh stack submit
214238
```

docs/src/content/docs/reference/cli.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,42 @@ gh stack unstack --local
312312
gh stack unstack feature-auth
313313
```
314314

315+
### `gh stack link`
316+
317+
Link PRs into a stack on GitHub without local tracking.
318+
319+
```sh
320+
gh stack link [flags] <branch-or-pr> <branch-or-pr> [...]
321+
```
322+
323+
Creates or updates a stack on GitHub from branch names or PR numbers. This command does not create or modify any `gh-stack` local tracking state. It is designed for users who manage branches with other tools locally (e.g., jj, Sapling, git-town) and want to simply open a stack of PRs.
324+
325+
Arguments are provided in stack order (bottom to top). Branch arguments are automatically pushed to the remote before creating or looking up PRs. For branches that already have open PRs, those PRs are used. For branches without PRs, new PRs are created automatically with the correct base branch chaining. Existing PRs whose base branch doesn't match the expected chain are corrected automatically.
326+
327+
If the PRs are not yet in a stack, a new stack is created. If some of the PRs are already in a stack, the existing stack is updated to include the new PRs. Existing PRs are never removed from a stack — the update is additive only.
328+
329+
| Flag | Description |
330+
|------|-------------|
331+
| `--base <branch>` | Base branch for the bottom of the stack (default: `main`) |
332+
| `--draft` | Create new PRs as drafts |
333+
| `--remote <name>` | Remote to push to (defaults to auto-detected remote) |
334+
335+
**Examples:**
336+
337+
```sh
338+
# Link branches into a stack (pushes, creates PRs, creates stack)
339+
gh stack link feature-auth feature-api feature-ui
340+
341+
# Link existing PRs by number
342+
gh stack link 10 20 30
343+
344+
# Add branches to an existing stack of PRs
345+
gh stack link 42 43 feature-auth feature-ui
346+
347+
# Use a different base branch and create PRs as drafts
348+
gh stack link --base develop --draft feat-a feat-b feat-c
349+
```
350+
315351
---
316352

317353
## Navigation

skills/gh-stack/SKILL.md

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,12 @@ git config remote.pushDefault origin # if multiple remotes exist (skips remo
5656
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`.
5757
3. **Always use `--auto` with `gh stack submit`** to auto-generate PR titles. Without `--auto`, `submit` prompts for a title for each new PR.
5858
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.
59+
5. **Use `--remote <name>` when multiple remotes are configured**, or pre-configure `git config remote.pushDefault origin`. Without this, `push`, `submit`, `sync`, `link`, and `checkout` trigger an interactive remote picker.
6060
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.
6161
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`.
6262
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.
6363
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.
64+
10. **Use `gh stack link` for external tool workflows.** When branches are managed by an external tool (jj, Sapling, etc.), use `gh stack link branch-a branch-b`. `link` does not rely on local tracking state and is intended for API-driven PR and stack management. Always provide at least 2 branch names or PR numbers.
6465

6566
**Never do any of the following — each triggers an interactive prompt or TUI that will hang:**
6667
-`gh stack view` or `gh stack view --short` — always use `gh stack view --json`
@@ -555,6 +556,54 @@ gh stack submit --auto --draft
555556

556557
---
557558

559+
### Link branches as a stack (no local tracking) — `gh stack link`
560+
561+
Link PRs into a stack on GitHub without creating any local tracking state. This is the recommended approach if you are managing stacked branches with other tools (jj, Sapling, git-town) and want to simply create GitHub Stacked PRs via an API.
562+
563+
```
564+
gh stack link [flags] <branch-or-pr> <branch-or-pr> [...]
565+
```
566+
567+
```bash
568+
# Link branches into a stack (pushes, creates PRs, creates stack)
569+
gh stack link branch-a branch-b branch-c
570+
571+
# Use a different base branch and create PRs as drafts
572+
gh stack link --base develop --draft branch-a branch-b branch-c
573+
574+
# Link existing PRs by number
575+
gh stack link 10 20 30
576+
577+
# Add branches to an existing stack of PRs
578+
gh stack link 42 43 feature-auth feature-ui
579+
```
580+
581+
| Flag | Description |
582+
|------|---------|
583+
| `--base <branch>` | Base branch for the bottom of the stack (default: `main`) |
584+
| `--draft` | Create new PRs as drafts |
585+
| `--remote <name>` | Remote to push to (use if multiple remotes exist) |
586+
587+
**Behavior:**
588+
589+
- Arguments are provided in stack order (bottom to top)
590+
- Each argument can be a branch name or a PR number. Numeric arguments are tried as PR numbers first; if no PR with that number exists, the argument is treated as a branch name
591+
- Branch arguments are pushed to the remote automatically (non-force, atomic)
592+
- For branches without open PRs, new PRs are created with auto-generated titles and the correct base branch chaining (first branch uses `--base`, subsequent branches use the previous branch)
593+
- Existing PRs whose base branch doesn't match the expected chain are corrected automatically
594+
- If the PRs are not yet in a stack, a new stack is created. If some PRs are already in a stack, the stack is updated (additive only — existing PRs are never removed)
595+
- Does **not** create or modify any local state
596+
597+
**Output (stderr):**
598+
599+
- `Pushing N branches to <remote>...`
600+
- `Found PR #N for branch <name>` for branches with existing PRs
601+
- `Created PR #N for <branch> (base: <base>)` for newly created PRs
602+
- `Updated base branch for PR #N to <base>` when base branches are corrected
603+
- `Created stack with N PRs` or `Updated stack to N PRs`
604+
605+
---
606+
558607
### Sync the stack — `gh stack sync`
559608

560609
Fetch, rebase, push, and sync PR state in a single command. This is the recommended command for routine synchronization.

0 commit comments

Comments
 (0)