Skip to content

Commit c85384a

Browse files
committed
update docs
1 parent 9be7bfe commit c85384a

5 files changed

Lines changed: 51 additions & 23 deletions

File tree

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,9 @@ Initialize a new stack in the current repository.
7676
gh stack init [flags] [branches...]
7777
```
7878

79-
Creates an entry in `.git/gh-stack` to track stack state. In interactive mode (no arguments), prompts you to name branches and offers to use the current branch as the first layer. In interactive mode, you'll also be prompted to set an optional branch prefix (unless adopting existing branches). When a prefix is set, branch names you enter are automatically prefixed. When explicit branch names are given, creates any that don't already exist (branching from the trunk). The trunk defaults to the repository's default branch unless overridden with `--base`.
79+
Initializes a new stack locally. In interactive mode (no arguments), prompts for a branch name and offers to use the current branch as the first layer. If a branch name contains slashes (e.g., `feat/api`), prompts if you would like to use a prefix (e.g., `feat/`) for all branches in the stack.
80+
81+
When explicit branch names are given, existing branches are adopted automatically and any missing branches are created. The trunk defaults to the repository's default branch unless overridden with `--base`.
8082

8183
Use `--numbered` with `--prefix` to enable auto-incrementing numbered branch names (`prefix/01`, `prefix/02`, …). Without `--numbered`, you'll always be prompted to provide a meaningful branch name.
8284

@@ -85,7 +87,6 @@ Enables `git rerere` automatically so that conflict resolutions are remembered a
8587
| Flag | Description |
8688
|------|-------------|
8789
| `-b, --base <branch>` | Trunk branch for the stack (defaults to the repository's default branch) |
88-
| `-a, --adopt` | Adopt existing branches into a stack instead of creating new ones |
8990
| `-p, --prefix <string>` | Set a branch name prefix for the stack |
9091
| `-n, --numbered` | Use auto-incrementing numbered branch names (requires `--prefix`) |
9192

@@ -102,7 +103,7 @@ gh stack init feature-auth feature-api feature-ui
102103
gh stack init --base develop feature-auth
103104

104105
# Adopt existing branches into a stack
105-
gh stack init --adopt feature-auth feature-api
106+
gh stack init feature-auth feature-api
106107

107108
# Set a prefix — you'll be prompted for a branch name
108109
gh stack init -p feat

docs/src/content/docs/faq.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,17 @@ You can also add PRs to an existing stack from the GitHub UI. See [Adding to an
3535

3636
Use `gh stack modify` to restructure a stack. It opens an interactive terminal UI where you can reorder, drop, fold (combine), and rename branches — then applies all changes at once. See the [Restructuring Stacks](/gh-stack/guides/modify/) guide for a full walkthrough.
3737

38-
Alternatively, you can manually tear down and re-create the stack with `gh stack unstack` and `gh stack init --adopt`:
38+
Alternatively, you can manually tear down and re-create the stack with `gh stack unstack` and `gh stack init`:
3939

4040
```sh
4141
# 1. Remove the stack
4242
gh stack unstack
4343

4444
# 2. Make structural changes (reorder, rename, delete branches)
45-
git branch -m old-name new-name
45+
git branch -m api-roots api-routes
4646

4747
# 3. Re-create the stack with the new structure
48-
gh stack init --adopt branch-1 branch-2 branch-3
48+
gh stack init db-migrations api-routes frontend
4949
```
5050

5151
### How do I delete my stack?
@@ -263,9 +263,9 @@ You can also use `--base` to specify a different trunk branch and `--open` to ma
263263
gh stack link --base develop --open change1 change2 change3
264264
```
265265

266-
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`:
266+
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 init`:
267267

268268
```bash
269-
gh stack init --adopt change1 change2 change3
269+
gh stack init change1 change2 change3
270270
gh stack submit
271271
```

docs/src/content/docs/guides/workflows.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,34 @@ This command:
137137

138138
If a conflict is detected during the rebase, all branches are restored to their original state, and you're advised to run `gh stack rebase` to resolve conflicts interactively.
139139

140+
## Existing Branches into a Stack
141+
142+
If you already have a set of branches that form a logical chain, you can organize them into a stack by passing them to `gh stack init`. Existing branches are adopted automatically — no special flags needed.
143+
144+
```sh
145+
# Adopt three existing branches into a stack (bottom to top)
146+
gh stack init feat/auth feat/api feat/ui
147+
```
148+
149+
The order matters: branches are listed from bottom (closest to trunk) to top (furthest from trunk). Any PRs already open for these branches are detected and linked to the stack.
150+
151+
You can also mix existing and new branches in one command:
152+
153+
```sh
154+
# feat/auth exists, feat/api-v2 will be created
155+
gh stack init feat/auth feat/api-v2
156+
```
157+
158+
After organizing branches into a stack, run `gh stack submit` to create a Stack on GitHub and link the PRs together.
159+
160+
```sh
161+
# View the new stack
162+
gh stack view
163+
164+
# Create/update PRs and link them as a Stack on GitHub
165+
gh stack submit
166+
```
167+
140168
## Structuring Your Stack
141169

142170
Think of a stack from the reviewer's perspective: the PRs should tell a **cohesive story**. A reviewer reading the PRs in sequence should understand the progression of changes.

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

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ Initialize a new stack in the current repository.
2727
gh stack init [flags] [branches...]
2828
```
2929

30-
Creates an entry in `.git/gh-stack` to track stack state. In interactive mode (no arguments), prompts you to name branches and offers to use the current branch as the first layer. You'll also be prompted to set an optional branch prefix. When a prefix is set, branch names you enter are automatically prefixed.
30+
Initializes a new stack locally. In interactive mode (no arguments), prompts for a branch name and offers to use the current branch as the first layer. If a branch name contains slashes (e.g., `feat/api`), prompts if you would like to use a prefix (e.g., `feat/`) for all branches in the stack.
3131

32-
When explicit branch names are given, creates any that don't already exist (branching from the trunk). The trunk defaults to the repository's default branch unless overridden with `--base`.
32+
When explicit branch names are given, existing branches are adopted automatically and any missing branches are created. The trunk defaults to the repository's default branch unless overridden with `--base`.
3333

3434
Use `--numbered` with `--prefix` to enable auto-incrementing branch names (`prefix/01`, `prefix/02`, …).
3535

@@ -38,7 +38,6 @@ Enables `git rerere` automatically so that conflict resolutions are remembered a
3838
| Flag | Description |
3939
|------|-------------|
4040
| `-b, --base <branch>` | Trunk branch for the stack (defaults to the repository's default branch) |
41-
| `-a, --adopt` | Adopt existing branches into a stack instead of creating new ones |
4241
| `-p, --prefix <string>` | Set a branch name prefix for the stack |
4342
| `-n, --numbered` | Use auto-incrementing numbered branch names (requires `--prefix`) |
4443

@@ -48,14 +47,14 @@ Enables `git rerere` automatically so that conflict resolutions are remembered a
4847
# Interactive — prompts for branch names
4948
gh stack init
5049

51-
# Non-interactive — specify branches upfront
52-
gh stack init feature-auth feature-api feature-ui
50+
# Non-interactive — specify first branch upfront
51+
gh stack init feature-auth
5352

5453
# Use a different trunk branch
5554
gh stack init --base develop feature-auth
5655

57-
# Adopt existing branches into a stack
58-
gh stack init --adopt feature-auth feature-api
56+
# Adopt or create multiple branches at once
57+
gh stack init feature-auth feature-api feature-ui
5958

6059
# Set a prefix — prompts for a branch name suffix
6160
gh stack init -p feat
@@ -235,7 +234,7 @@ You must have a branch from the stack checked out locally. The command targets t
235234

236235
Deletes the stack on GitHub first, if it exists, then removes it from local tracking. If the remote deletion fails, the local state is left untouched so you can retry. Use `--local` to skip the remote deletion and only remove local tracking.
237236

238-
This is useful when you need to restructure a stack — remove a branch, reorder branches, rename branches, or make other large changes. After unstacking, use `gh stack init --adopt` to re-create the stack with the desired structure.
237+
This is useful when you need to restructure a stack — 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 — existing branches are adopted automatically.
239238

240239
| Flag | Description |
241240
|------|-------------|

skills/gh-stack/SKILL.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,8 @@ Small, incidental fixes (e.g., fixing a typo you noticed) can go in the current
141141
|------|---------|
142142
| Create a stack (recommended) | `gh stack init -p feat auth` |
143143
| Create a stack without prefix | `gh stack init auth` |
144-
| Adopt existing branches | `gh stack init --adopt branch-a branch-b` |
144+
| Create a stack of multiple branches | `gh stack init auth api frontend` |
145+
| Adopt existing branches | `gh stack init existing-branch-a existing-branch-b` |
145146
| Set custom trunk | `gh stack init --base develop branch-a` |
146147
| Add a branch to stack (suffix only if prefix set) | `gh stack add api-routes` |
147148
| Add branch + stage all + commit | `gh stack add -Am "message" api-routes` |
@@ -387,7 +388,7 @@ gh stack unstack
387388
git branch -m old-branch-1 new-branch-1
388389

389390
# 3. Re-create the stack with the new structure
390-
gh stack init --base main --adopt new-branch-1 new-branch-2 new-branch-3
391+
gh stack init --base main new-branch-1 new-branch-2 new-branch-3
391392
```
392393

393394
---
@@ -417,21 +418,20 @@ gh stack init branch-a branch-b branch-c
417418
# Use a different trunk branch
418419
gh stack init --base develop branch-a branch-b
419420

420-
# Adopt existing branches into a stack
421-
gh stack init --adopt branch-a branch-b branch-c
421+
# Adopt existing branches into a stack (handled automatically if the branches exist)
422+
gh stack init branch-a branch-b branch-c
422423
```
423424

424425
| Flag | Description |
425426
|------|-------------|
426427
| `-b, --base <branch>` | Trunk branch (defaults to the repo's default branch) |
427-
| `-a, --adopt` | Adopt existing branches instead of creating new ones |
428428
| `-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`) |
429429

430430
**Behavior:**
431431

432432
- Using `-p` is recommended — it simplifies branch naming for subsequent `add` calls
433433
- Creates any branches that don't already exist (branching from the trunk branch)
434-
- In `--adopt` mode: validates all branches exist, rejects if any is already in a stack or has an existing PR
434+
- Existing branches are adopted automatically; missing branches are created from the trunk
435435
- Checks out the last branch in the list
436436
- 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
437437

@@ -797,7 +797,7 @@ gh stack unstack [flags]
797797
```bash
798798
# Tear down the stack (locally and on GitHub), then rebuild
799799
gh stack unstack
800-
gh stack init --base main --adopt branch-2 branch-1 branch-3 # reordered
800+
gh stack init --base main branch-2 branch-1 branch-3 # reordered
801801

802802
# Only remove local tracking (keep the stack on GitHub)
803803
gh stack unstack --local

0 commit comments

Comments
 (0)