Skip to content

Commit ea4d716

Browse files
committed
update unstack docs
1 parent f308f8a commit ea4d716

4 files changed

Lines changed: 30 additions & 14 deletions

File tree

README.md

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -477,26 +477,33 @@ gh stack view --json
477477

478478
### `gh stack unstack`
479479

480-
Remove a stack from local tracking and delete it on GitHub. Also available as `gh stack delete`.
480+
Remove a stack from local tracking and unstack it on GitHub. Also available as `gh stack delete`.
481481

482482
```
483-
gh stack unstack [flags]
483+
gh stack unstack [<stack-number>] [flags]
484484
```
485485

486-
You must have an active stack checked out locally. The command targets the active stack — the one that contains the currently checked out branch.
486+
With no argument, the command targets the active stack — the one that contains the currently checked out branch — unstacking it on GitHub and removing local tracking.
487487

488-
Deletes the stack on GitHub first, if it exists, then removes local tracking. Use `--local` to only remove from local tracking.
488+
Provide a stack number (the identifier shown in the github.com stack UI) to unstack a specific stack on GitHub. This works from anywhere in the repository, whether or not the stack is checked out locally — the number is unstacked directly through the GitHub API. If the stack is also tracked locally, its local tracking is removed as well.
489+
490+
Use `--local` to only remove local tracking without contacting GitHub.
491+
492+
GitHub decides which pull requests can be unstacked: PRs that are queued for merge or have auto-merge enabled are left stacked. When some pull requests remain stacked, the stack is kept (and local tracking, if any, is unchanged).
489493

490494
| Flag | Description |
491495
|------|-------------|
492-
| `--local` | Only delete the stack locally (keep it on GitHub) |
496+
| `--local` | Only remove the stack locally (keep it on GitHub) |
493497

494498
**Examples:**
495499

496500
```sh
497-
# Remove the stack from local tracking and GitHub
501+
# Remove the current stack from local tracking and GitHub
498502
gh stack unstack
499503

504+
# Unstack a specific stack by its number
505+
gh stack unstack 7
506+
500507
# Only remove local tracking
501508
gh stack unstack --local
502509
```

docs/src/content/docs/faq.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ gh stack init db-migrations api-routes frontend
5050

5151
### How do I delete my stack?
5252

53-
**From the CLI** — Run `gh stack unstack` (or `gh stack delete`) to delete the stack on GitHub and remove local tracking. Use `--local` to only remove local tracking.
53+
**From the CLI** — Run `gh stack unstack` (or `gh stack delete`) to delete the stack on GitHub and remove local tracking. You can also unstack any stack by its number from anywhere in the repository — `gh stack unstack 7` — whether or not it's checked out locally. Use `--local` to only remove local tracking.
5454

5555
**From the UI** — You can unstack PRs from the GitHub UI — see [Unstacking](/gh-stack/guides/ui/#unstacking) for a walkthrough. This dissolves the association between PRs, turning them back into standard independent PRs.
5656

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -240,9 +240,11 @@ Remove a stack from local tracking and unstack it on GitHub. Also available as `
240240
gh stack unstack [<stack-number>] [flags]
241241
```
242242

243-
With no argument, the command targets the active stack — the one that contains the currently checked out branch. Provide a stack number (the identifier shown in the github.com stack UI) to target a specific locally tracked stack instead.
243+
With no argument, the command targets the active stack — the one that contains the currently checked out branch — unstacking it on GitHub and removing local tracking.
244244

245-
PRs that are merged, merging, or queued for merge cannot be removed from a stack on GitHub and are left part of the stack. When every pull request is removed, the stack is dissolved and local tracking is removed; when some pull requests remain stacked, local tracking is kept. Use `--local` to skip the remote operation and only remove local tracking.
245+
Provide a stack number (the identifier shown in the github.com stack UI) to unstack a specific stack on GitHub. This works from anywhere in the repository, whether or not the stack is checked out locally — the stack is unstacked directly through the GitHub API. When the stack is also available locally, its local tracking is removed as well.
246+
247+
PRs that are merged, merging, or queued for merge cannot be removed from a stack on GitHub and are left part of the stack. When every pull request is removed, the stack is dissolved and any local tracking is removed; when some pull requests remain stacked, the stack is kept and local tracking, if any, is unchanged. Use `--local` to skip the remote operation and only remove local tracking.
246248

247249
This is useful when you need to restructure a stack — remove a branch, insert a branch, reorder branches, rename branches, or make other large changes. After unstacking, use `gh stack init` to re-create the stack with the desired structure — existing branches are adopted automatically.
248250

@@ -256,7 +258,7 @@ This is useful when you need to restructure a stack — remove a branch, insert
256258
# Unstack the current stack on GitHub and remove local tracking
257259
gh stack unstack
258260

259-
# Unstack a specific stack by its stack number
261+
# Unstack a specific stack by its numbe
260262
gh stack unstack 7
261263

262264
# Only remove local tracking

skills/gh-stack/SKILL.md

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -815,24 +815,31 @@ When a branch name is provided, the command resolves it against locally tracked
815815

816816
Tear down a stack so you can restructure it — remove a branch, reorder branches, rename branches, or make other large changes. After unstacking, use `gh stack init` to re-create the stack with the desired structure.
817817

818-
You must have a branch from the stack checked out locally. The command targets the active stack — the one that contains the currently checked out branch.
818+
With no argument, the command targets the active stack — the one containing the currently checked out branch — unstacking it on GitHub and removing local tracking.
819+
820+
Provide a stack number to unstack a specific stack on GitHub. This works from anywhere in the repository, whether or not the stack is checked out locally — the number is unstacked directly through the GitHub API (like `gh stack link`, no local tracking required). If the stack is also tracked locally, its local tracking is removed as well.
819821

820822
```
821-
gh stack unstack [flags]
823+
gh stack unstack [<stack-number>] [flags]
822824
```
823825

824826
```bash
825-
# Tear down the stack (locally and on GitHub), then rebuild
827+
# Tear down the current stack (locally and on GitHub), then rebuild
826828
gh stack unstack
827829
gh stack init --base main branch-2 branch-1 branch-3 # reordered
828830

831+
# Unstack a specific stack by its number, from anywhere in the repo
832+
gh stack unstack 7
833+
829834
# Only remove local tracking (keep the stack on GitHub)
830835
gh stack unstack --local
831836
```
832837

833838
| Flag | Description |
834839
|------|-------------|
835-
| `--local` | Only delete the stack locally (keep it on GitHub) |
840+
| `--local` | Only remove the stack locally (keep it on GitHub); never contacts GitHub |
841+
842+
> **Note for agents:** `gh stack unstack <number>` is a remote-first API wrapper — it unstacks on GitHub by number from anywhere in the repo, tracked locally or not, and is safe for non-interactive use. `--local` never contacts GitHub; combining `--local` with a number that isn't tracked locally is an error. An unknown stack number returns a "not found on GitHub" error (exit code 2).
836843
837844
---
838845

0 commit comments

Comments
 (0)