Skip to content

Commit c9b61f2

Browse files
authored
Merge pull request #10 from github/skarim/remote-stack-operations
Update commands to use create and update stack APIs
2 parents facd16d + cb7f9fa commit c9b61f2

File tree

18 files changed

+1461
-523
lines changed

18 files changed

+1461
-523
lines changed

README.md

Lines changed: 35 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,14 @@ gh stack add auth-layer
3434
gh stack add api-endpoints
3535
# ... make commits ...
3636

37-
# Push all branches and create/update PRs
37+
# Push all branches
3838
gh stack push
3939

4040
# View the stack
4141
gh stack view
42+
43+
# Open a stack of PRs
44+
gh stack submit
4245
```
4346

4447
## How it works
@@ -55,7 +58,7 @@ main (trunk)
5558

5659
The **bottom** of the stack is the branch closest to the trunk, and the **top** is the branch furthest from it. Each branch inherits from the one below it. Navigation commands (`up`, `down`, `top`, `bottom`) follow this model: `up` moves away from trunk, `down` moves toward it.
5760

58-
When you push, `gh stack` creates one PR per branch. Each PR's base is set to the branch below it in the stack, so reviewers see only the diff for that layer.
61+
When you submit, `gh stack` creates one PR per branch and links them together as a **Stack** on GitHub. Each PR's base is set to the branch below it in the stack, so reviewers see only the diff for that layer.
5962

6063
### Local tracking
6164

@@ -253,84 +256,74 @@ gh stack sync
253256

254257
### `gh stack push`
255258

256-
Push all branches in the current stack and create or update pull requests.
259+
Push all branches in the current stack to the remote.
257260

258261
```
259262
gh stack push [flags]
260263
```
261264

262-
Pushes every branch to the remote, then for each branch either creates a new PR (with the correct base branch) or updates the base of an existing PR if it has changed. Uses `--force-with-lease` by default to safely update rebased branches.
263-
264-
When creating new PRs, you will be prompted to enter a title for each one. Press Enter to accept the default (branch name), or use `--auto` to skip prompting entirely.
265+
Pushes every branch to the remote using `--force-with-lease --atomic`. This is a lightweight wrapper around `git push` that knows about all branches in the stack. It does not create or update pull requests — use `gh stack submit` for that.
265266

266267
| Flag | Description |
267268
|------|-------------|
268-
| `--auto` | Use auto-generated PR titles without prompting |
269-
| `--draft` | Create new PRs as drafts |
270-
| `--skip-prs` | Push branches without creating or updating PRs |
271269
| `--remote <name>` | Remote to push to (defaults to auto-detected remote) |
272270

273271
**Examples:**
274272

275273
```sh
276274
gh stack push
277-
gh stack push --auto
278-
gh stack push --draft
279-
gh stack push --skip-prs
275+
gh stack push --remote upstream
280276
```
281277

282-
### `gh stack view`
278+
### `gh stack submit`
283279

284-
View the current stack.
280+
Push all branches and create/update PRs and the stack on GitHub.
285281

286282
```
287-
gh stack view [flags]
283+
gh stack submit [flags]
288284
```
289285

290-
Shows all branches in the stack, their ordering, PR links, and the most recent commit with a relative timestamp. Output is piped through a pager (respects `GIT_PAGER`, `PAGER`, or defaults to `less -R`).
286+
Creates a Stacked PR for every branch in the stack, pushing branches to the remote.
287+
288+
After creating PRs, `submit` automatically creates a **Stack** on GitHub to link the PRs together. If the stack already exists on GitHub (e.g., from a previous submit), new PRs will be added to the top of the stack.
289+
290+
When creating new PRs, you will be prompted to enter a title for each one. Press Enter to accept the default (branch name), or use `--auto` to skip prompting entirely.
291291

292292
| Flag | Description |
293293
|------|-------------|
294-
| `-s, --short` | Compact output (branch names only) |
295-
| `--json` | Output stack data as JSON |
294+
| `--auto` | Use auto-generated PR titles without prompting |
295+
| `--draft` | Create new PRs as drafts |
296+
| `--remote <name>` | Remote to push to (defaults to auto-detected remote) |
296297

297298
**Examples:**
298299

299300
```sh
300-
gh stack view
301-
gh stack view --short
302-
gh stack view --json
301+
gh stack submit
302+
gh stack submit --auto
303+
gh stack submit --draft
303304
```
304305

305-
### `gh stack unstack`
306+
### `gh stack view`
306307

307-
Remove a stack from local tracking and optionally delete it on GitHub.
308+
View the current stack.
308309

309310
```
310-
gh stack unstack [branch] [flags]
311+
gh stack view [flags]
311312
```
312313

313-
If no branch is specified, uses the current branch to find the stack. By default, the stack is removed from both local tracking and GitHub. Use `--local` to only remove the local tracking entry.
314+
Shows all branches in the stack, their ordering, PR links, and the most recent commit with a relative timestamp. Output is piped through a pager (respects `GIT_PAGER`, `PAGER`, or defaults to `less -R`).
314315

315316
| Flag | Description |
316317
|------|-------------|
317-
| `--local` | Only delete the stack locally (keep it on GitHub) |
318-
319-
| Argument | Description |
320-
|----------|-------------|
321-
| `[branch]` | A branch in the stack to delete (defaults to the current branch) |
318+
| `-s, --short` | Compact output (branch names only) |
319+
| `--json` | Output stack data as JSON |
322320

323321
**Examples:**
324322

325323
```sh
326-
# Remove the stack from local tracking and GitHub
327-
gh stack unstack
328-
329-
# Only remove local tracking
330-
gh stack unstack --local
331-
332-
# Specify a branch to identify the stack
333-
gh stack unstack feature-auth
324+
gh stack view
325+
gh stack view --short
326+
gh stack view --json
334327
```
335328

336329
### `gh stack merge`
@@ -399,8 +392,8 @@ gh stack add auth-middleware
399392
gh stack add api-routes
400393
# ... write code, make commits ...
401394

402-
# 4. Push everything and create PRs
403-
gh stack push
395+
# 4. Push everything and create Stacked PRs
396+
gh stack submit
404397

405398
# 5. Reviewer requests changes on the first PR
406399
gh stack bottom
@@ -409,7 +402,7 @@ gh stack bottom
409402
# 6. Rebase the rest of the stack on top of your fix
410403
gh stack rebase
411404

412-
# 7. Push the updated stack
405+
# 7. Push the updated branches
413406
gh stack push
414407

415408
# 8. When the first PR is merged, sync the stack
@@ -450,7 +443,7 @@ gh stack add -Am "Frontend components"
450443
# → feat/02 already has commits, creates feat/03 and commits there
451444

452445
# 7. Push everything and create PRs
453-
gh stack push
446+
gh stack submit
454447
```
455448

456449
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.

cmd/init.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ func runInit(cfg *config.Config, opts *initOptions) error {
351351
}
352352

353353
cfg.Printf("To add a new layer to your stack, run `%s`", cfg.ColorCyan("gh stack add"))
354-
cfg.Printf("When you're ready to push to GitHub and open a stack of PRs, run `%s`", cfg.ColorCyan("gh stack push"))
354+
cfg.Printf("When you're ready to push to GitHub and open a stack of PRs, run `%s`", cfg.ColorCyan("gh stack submit"))
355355

356356
return nil
357357
}

cmd/merge.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ func runMerge(cfg *config.Config, target string) error {
6969

7070
if br.PullRequest == nil {
7171
cfg.Errorf("no pull request found for branch %q", br.Branch)
72-
cfg.Printf(" Run %s to create PRs for this stack.", cfg.ColorCyan("gh stack push"))
72+
cfg.Printf(" Run %s to create PRs for this stack.", cfg.ColorCyan("gh stack submit"))
7373
return ErrSilent
7474
}
7575

cmd/merge_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ func TestMerge_NoPullRequest(t *testing.T) {
4343

4444
assert.ErrorIs(t, err, ErrSilent)
4545
assert.Contains(t, output, "no pull request found")
46-
assert.Contains(t, output, "gh stack push")
46+
assert.Contains(t, output, "gh stack submit")
4747
}
4848

4949
func TestMerge_AlreadyMerged(t *testing.T) {

0 commit comments

Comments
 (0)