Skip to content

Commit 575f034

Browse files
committed
docs: Add stacked PR workflow with gh stack guidance
1 parent 26fe579 commit 575f034

1 file changed

Lines changed: 36 additions & 1 deletion

File tree

docs/GIT_WORKFLOW.md

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,39 @@ Before committing, agents must verify:
4747
2. `mise run test` passes.
4848
3. No unrelated changes are staged — keep commits focused.
4949

50-
If a commit includes a new feature, the commit should include the tests for that feature.
50+
If a commit includes a new feature, the commit should include the tests for that feature.
51+
52+
## Stacked pull requests
53+
54+
Use a stack when a change genuinely depends on another PR that hasn't merged yet — e.g. a bug fix that builds on an in-flight feature branch, or a large feature deliberately split into reviewable layers. Independent work still gets its own branch off `main` and its own standalone PR; don't stack things that don't depend on each other.
55+
56+
This repo uses **GitHub's native stacked pull requests** (public preview), managed through the `gh stack` CLI extension (`github/gh-stack`) — not a manually chosen `--base` branch. A PR whose base happens to equal another PR's head branch is *not* the same thing: GitHub only renders the stack map, auto-rebases upper layers, and retargets a PR's base automatically when the merge below it lands if the PR was created through `gh stack`. Always use the extension; never approximate a stack with `git checkout -b` + `gh pr create --base <branch>`.
57+
58+
Install once per machine: `gh extension install github/gh-stack`.
59+
60+
**Starting a new stack:**
61+
62+
```bash
63+
gh stack init # first branch of the stack, targets main
64+
git add . && git commit -m "..."
65+
gh stack add my-next-layer # new branch on top of the current one
66+
git add . && git commit -m "..."
67+
gh stack push # push all branches to origin
68+
gh stack submit # create/update the linked PRs on GitHub
69+
```
70+
71+
`gh stack add -Am "message" branch-name` stages, commits, and creates the next layer in one step.
72+
73+
**Adding a layer to an existing stack** (e.g. implementing an issue that's a prerequisite for, or builds on, a PR already open in the stack):
74+
75+
```bash
76+
gh stack checkout <PR#> # discovers and tracks the stack locally if not already tracked
77+
gh stack add my-new-layer # branches off the current top of the stack
78+
# ... commit work ...
79+
gh stack push
80+
gh stack submit
81+
```
82+
83+
`gh stack checkout` accepts a stack number, PR number/URL, or branch name, and will pull an untracked-locally stack down from GitHub if needed — run it before assuming a stack has to be recreated from scratch.
84+
85+
Other useful commands: `gh stack view` (show the current stack and its PR links), `gh stack sync` (pull remote changes into the local stack), `gh stack rebase` (rebase the whole stack after the trunk moves), `gh stack merge` (merge the stack in order).

0 commit comments

Comments
 (0)