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
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`.
57
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
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.
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.
60
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.
61
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`.
62
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.
63
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.
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.
64
65
65
66
**Never do any of the following — each triggers an interactive prompt or TUI that will hang:**
66
67
- ❌ `gh stack view` or `gh stack view --short` — always use `gh stack view --json`
- Pushes all active (non-merged) branches atomically (`--force-with-lease --atomic`)
540
541
- Creates a new PR for each branch that doesn't have one (base set to the first non-merged ancestor branch)
541
542
- After creating PRs, links them together as a **Stack** on GitHub (requires the repository to have stacks enabled)
543
+
- If stacks are not available (exit code 9), the repository does not have stacked PRs enabled. In interactive mode, `submit` offers to create regular (unstacked) PRs instead. In non-interactive mode, it exits with code 9.
542
544
- Syncs PR metadata for branches that already have PRs
### 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
+
557
607
### Sync the stack — `gh stack sync`
558
608
559
609
Fetch, rebase, push, and sync PR state in a single command. This is the recommended command for routine synchronization.
@@ -570,7 +620,7 @@ gh stack sync [flags]
570
620
571
621
1.**Fetch** latest changes from the remote
572
622
2.**Fast-forward trunk** to match remote (skips if already up to date, warns if diverged)
573
-
3.**Cascade rebase** all stack branches onto their updated parents (only if trunk moved). Handles squash-merged PRs automatically. If a conflict is detected, **all branches are restored** to their pre-rebase state and the command exits with code 3 — see [Handle rebase conflicts](#handle-rebase-conflicts-agent-workflow) for the resolution workflow
623
+
3.**Cascade rebase** all stack branches onto their updated parents (only if trunk moved). Handles merged PRs automatically. If a conflict is detected, **all branches are restored** to their pre-rebase state and the command exits with code 3 — see [Handle rebase conflicts](#handle-rebase-conflicts-agent-workflow) for the resolution workflow
574
624
4.**Push** all active branches atomically
575
625
5.**Sync PR state** from GitHub and report the status of each PR
576
626
@@ -625,7 +675,7 @@ gh stack rebase --abort
625
675
626
676
**Conflict handling:** See [Handle rebase conflicts](#handle-rebase-conflicts-agent-workflow) in the Workflows section for the full resolution workflow.
627
677
628
-
**Squash-merge detection:** If a branch's PR was squash-merged on GitHub, the rebase automatically handles this and correctly replays commits on top of the merge target.
678
+
**Merged PR detection:** If a branch's PR was merged on GitHub, the rebase automatically handles this using `--onto` mode and correctly replays commits on top of the merge target.
629
679
630
680
**Rerere (conflict memory):**`git rerere` is enabled by `init` so previously resolved conflicts are auto-resolved in future rebases.
631
681
@@ -783,6 +833,7 @@ gh stack unstack feature-auth
783
833
| 6 | Disambiguation required | A branch belongs to multiple stacks. Run `gh stack checkout <specific-branch>` to switch to a non-shared branch first |
784
834
| 7 | Rebase already in progress | Run `gh stack rebase --continue` (after resolving conflicts) or `gh stack rebase --abort` to start over |
785
835
| 8 | Stack is locked | Another `gh stack` process is writing the stack file. Wait and retry — the lock times out after 5 seconds |
836
+
| 9 | Stacked PRs unavailable | The repository does not have stacked PRs enabled. `submit` will offer to create regular (unstacked) PRs in interactive mode |
0 commit comments