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
+77-3Lines changed: 77 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -59,14 +59,15 @@ Initialize a new stack in the current repository.
59
59
gh stack init [branches...] [flags]
60
60
```
61
61
62
-
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. 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`.
62
+
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 for auto-naming (unless adopting existing branches). 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`.
63
63
64
64
Enables `git rerere` automatically so that conflict resolutions are remembered across rebases.
65
65
66
66
| Flag | Description |
67
67
|------|-------------|
68
68
|`-b, --base <branch>`| Trunk branch for the stack (defaults to the repository's default branch) |
69
69
|`-a, --adopt`| Adopt existing branches into a stack instead of creating new ones |
70
+
|`-p, --prefix <string>`| Set a branch name prefix for the stack |
Creates a new branch at the current HEAD, adds it to the top of the stack, and checks it out. Must be run while on the topmost branch of a stack. If no branch name is given, prompts for one.
96
100
101
+
You can optionally stage changes and create a commit as part of the `add` flow. When `-m` is provided without an explicit branch name, the branch name is auto-generated. Auto-generated names use either numbered format (`prefix/01`, `prefix/02`) or date+slug format depending on prefix configuration and existing branch naming patterns.
102
+
103
+
| Flag | Description |
104
+
|------|-------------|
105
+
|`-a, --all`| Stage all changes (including untracked files); requires `-m`|
106
+
|`-u, --update`| Stage changes to tracked files only; requires `-m`|
107
+
|`-m, --message <string>`| Create a commit with this message before creating the branch |
108
+
109
+
> **Note:**`-a` and `-u` are mutually exclusive.
110
+
97
111
**Examples:**
98
112
99
113
```sh
114
+
# Create a branch by name
100
115
gh stack add api-routes
101
-
gh stack add # prompts for name
116
+
117
+
# Prompt for a branch name interactively
118
+
gh stack add
119
+
120
+
# Stage all changes, commit, and auto-generate the branch name
121
+
gh stack add -am "Add login endpoint"
122
+
123
+
# Stage only tracked files, commit, and auto-generate the branch name
124
+
gh stack add -um "Fix auth bug"
125
+
126
+
# Commit already-staged changes and auto-generate the branch name
127
+
gh stack add -m "Add user model"
128
+
129
+
# Stage all changes, commit, and use an explicit branch name
130
+
gh stack add -am "Add tests" test-layer
131
+
132
+
# Stage only tracked files, commit, and use an explicit branch name
133
+
gh stack add -um "Update docs" docs-layer
134
+
135
+
# Commit already-staged changes and use an explicit branch name
136
+
gh stack add -m "Refactor utils" cleanup-layer
102
137
```
103
138
104
139
### `gh stack checkout`
@@ -355,3 +390,42 @@ gh stack push
355
390
# 8. When the first PR is merged, sync the stack
356
391
gh stack sync
357
392
```
393
+
394
+
## Abbreviated workflow
395
+
396
+
If you want to minimize keystrokes, use a branch prefix and the `-am` flags to fold staging, committing, and branch creation into a single command. Branch names are auto-generated from your commit messages.
397
+
398
+
When a branch has no commits yet (e.g., right after `init`), `add -am` stages and commits directly on that branch instead of creating a new one. Once a branch has commits, `add -am` creates a new branch, checks it out, and commits there.
399
+
400
+
```sh
401
+
# 1. Start a stack with a prefix
402
+
gh stack init -p feat
403
+
# → creates feat/01 and checks it out
404
+
405
+
# 2. Write code for the first layer
406
+
# ... write code ...
407
+
408
+
# 3. Stage and commit on the current branch
409
+
gh stack add -am "Auth middleware"
410
+
# → feat/01 has no commits yet, so the commit lands here
411
+
# (no new branch is created)
412
+
413
+
# 4. Write code for the next layer
414
+
# ... write code ...
415
+
416
+
# 5. Create the next branch and commit
417
+
gh stack add -am "API routes"
418
+
# → feat/01 already has commits, so a new branch feat/02 is
419
+
# created, checked out, and the commit lands there
420
+
421
+
# 6. Keep going
422
+
# ... write code ...
423
+
424
+
gh stack add -am "Frontend components"
425
+
# → feat/02 already has commits, creates feat/03 and commits there
426
+
427
+
# 7. Push everything and create PRs
428
+
gh stack push
429
+
```
430
+
431
+
Compared to the typical workflow, there's no need to name branches, run `git add`, or run `git commit` separately. Each `gh stack add -am "..."` does it all.
0 commit comments