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
Copy file name to clipboardExpand all lines: README.md
+4-3Lines changed: 4 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -76,7 +76,9 @@ Initialize a new stack in the current repository.
76
76
gh stack init [flags] [branches...]
77
77
```
78
78
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`.
80
82
81
83
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.
82
84
@@ -85,7 +87,6 @@ Enables `git rerere` automatically so that conflict resolutions are remembered a
85
87
| Flag | Description |
86
88
|------|-------------|
87
89
|`-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 |
89
90
|`-p, --prefix <string>`| Set a branch name prefix for the stack |
90
91
|`-n, --numbered`| Use auto-incrementing numbered branch names (requires `--prefix`) |
Copy file name to clipboardExpand all lines: docs/src/content/docs/faq.md
+5-5Lines changed: 5 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -35,17 +35,17 @@ You can also add PRs to an existing stack from the GitHub UI. See [Adding to an
35
35
36
36
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.
37
37
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`:
39
39
40
40
```sh
41
41
# 1. Remove the stack
42
42
gh stack unstack
43
43
44
44
# 2. Make structural changes (reorder, rename, delete branches)
45
-
git branch -m old-name new-name
45
+
git branch -m api-roots api-routes
46
46
47
47
# 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
49
49
```
50
50
51
51
### 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
263
263
gh stack link --base develop --open change1 change2 change3
264
264
```
265
265
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`:
Copy file name to clipboardExpand all lines: docs/src/content/docs/guides/workflows.md
+28Lines changed: 28 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -137,6 +137,34 @@ This command:
137
137
138
138
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.
139
139
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
+
140
168
## Structuring Your Stack
141
169
142
170
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.
Copy file name to clipboardExpand all lines: docs/src/content/docs/reference/cli.md
+7-8Lines changed: 7 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -27,9 +27,9 @@ Initialize a new stack in the current repository.
27
27
gh stack init [flags] [branches...]
28
28
```
29
29
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.
31
31
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`.
33
33
34
34
Use `--numbered` with `--prefix` to enable auto-incrementing branch names (`prefix/01`, `prefix/02`, …).
35
35
@@ -38,7 +38,6 @@ Enables `git rerere` automatically so that conflict resolutions are remembered a
38
38
| Flag | Description |
39
39
|------|-------------|
40
40
|`-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 |
42
41
|`-p, --prefix <string>`| Set a branch name prefix for the stack |
43
42
|`-n, --numbered`| Use auto-incrementing numbered branch names (requires `--prefix`) |
44
43
@@ -48,14 +47,14 @@ Enables `git rerere` automatically so that conflict resolutions are remembered a
48
47
# Interactive — prompts for branch names
49
48
gh stack init
50
49
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
53
52
54
53
# Use a different trunk branch
55
54
gh stack init --base develop feature-auth
56
55
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
59
58
60
59
# Set a prefix — prompts for a branch name suffix
61
60
gh stack init -p feat
@@ -235,7 +234,7 @@ You must have a branch from the stack checked out locally. The command targets t
235
234
236
235
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.
237
236
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.
# Adopt existing branches into a stack (handled automatically if the branches exist)
422
+
gh stack init branch-a branch-b branch-c
422
423
```
423
424
424
425
| Flag | Description |
425
426
|------|-------------|
426
427
|`-b, --base <branch>`| Trunk branch (defaults to the repo's default branch) |
427
-
|`-a, --adopt`| Adopt existing branches instead of creating new ones |
428
428
|`-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`) |
429
429
430
430
**Behavior:**
431
431
432
432
- Using `-p` is recommended — it simplifies branch naming for subsequent `add` calls
433
433
- 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
435
435
- Checks out the last branch in the list
436
436
- 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
437
437
@@ -797,7 +797,7 @@ gh stack unstack [flags]
797
797
```bash
798
798
# Tear down the stack (locally and on GitHub), then rebuild
0 commit comments