Sharp, zero-dependency stacked diffs for Git and GitHub β built for humans and coding agents.
st turns stacked branches into a fast, predictable loop: break large changes into small reviewable PRs, amend lower branches without hand-rebasing the chain, and let st keep your GitHub PR bases, stack links, and merged branches in sync.
# 1. Build a 2-PR stack
git add auth.go && st create feat-auth -m "Add token validator"
git add api.go && st create feat-api -m "Wire auth into /v1 endpoints"
# 2. Push & open stacked GitHub PRs (with auto-maintained stack links)
st submit
# pushed feat-auth
# pushed feat-api
#
# pull requests:
# #41 feat-auth -> main (created) https://github.com/org/repo/pull/41
# #42 feat-api -> feat-auth (created) https://github.com/org/repo/pull/42
# 3. See stack + live PR & CI status
st log --pr
# β feat-api [#42 β] Wire auth into /v1 endpoints
# β feat-auth [#41 β] Add token validator
# β main
# 4. Address review on PR #41 β PR #42 restacks automatically
st down
git add auth.go && st modify && st submit
# 5. PR #41 merges on GitHub β prune, advance HEAD, restack, retarget PR #42 -> main, and push
st sync --submit- Native GitHub stacked PRs via
ghβ no extra account or hosted service. On GitHub remotes withghinstalled,st submitretargets open PR bases before pushing (so GitHub never auto-closes child PRs), force-pushes with--force-with-lease, creates missing PRs bottom-up, and maintains a clean navigation block in multi-PR stacks without touching your PR description. Pass--no-pr(or skipgh) for push-only Git mode. - One-command post-merge drill (
st sync --submit). Fetches trunk, detects merged and squash-merged PRs (via GitHub PR state and 3-waygit merge-tree), prunes the merged branch, moves you to the next branch in the stack, restacks descendants, retargets the new bottom PR tomain, and force-pushes β all in one shot. - Built for coding agents & automation.
Zero interactive prompts, structured
--jsonoutput across the CLI, stable exit codes (2conflict,3uninitialized,4dirty tree,5lock held), advisory locking for concurrent runs, andst guidefor instant self-orientation. - Untracked-file safe.
Untracked scratch files (
plans/, notes, local logs) never blockrestack,sync,modify,delete,onto, orsquash, and never leak into commits.st modifydefaults to staged changes only;-astages modified tracked files only (matchinggit commit -a). - Plain Git underneath, zero dependencies.
Written in pure Go using only the standard library. All stack metadata lives locally in
.git/stacked/state.jsonβ never committed, never pushed, and automatically shared acrossgit worktrees (withoutstever creating or deleting worktrees on disk).
One-line installer (macOS & Linux, amd64/arm64 β verifies minisign signature & SHA-256 checksums):
curl -fsSL https://raw.githubusercontent.com/andyrewlee/stacked/main/install.sh | shInstalls st to /usr/local/bin (override with INSTALL_DIR). Releases are signed with minisign (public key in stacked.pub); if minisign isn't installed locally, pass ST_ALLOW_UNVERIFIED=1 to fall back to checksum-only verification.
With Go:
go install github.com/andyrewlee/stacked/cmd/st@latestPrebuilt archives: download stacked_<version>_<os>_<arch>.tar.gz and checksums.txt from the releases page.
From source: requires Go 1.26+ and Git 2.17+ on your PATH (Git 2.31+ recommended for native common-dir path resolution; Git 2.26+ preserves empty commits during restack). Optional native GitHub PR automation uses your existing authenticated gh CLI. Running the full make ci gate also needs golangci-lint v2: go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.12.2.
git clone https://github.com/andyrewlee/stacked.git
cd stacked
make build # produces ./st with version stamped from git
./st versionst init # auto-detects trunk (origin/HEAD -> current branch -> main)
st init --trunk main # or specify explicitlyAlready have local branches? Adopt them without recreating anything:
st track # track current branch (infers parent from commit graph)
st track --all # adopt every untracked local branch in one pass# Branch 1 on main
git add schema.sql && st create db-schema -m "Add users table"
# Branch 2 stacked on db-schema
git add store.go && st create user-store -m "Add UserStore queries"
# Branch 3 stacked on user-store
git add handler.go && st create user-api -m "Expose /users endpoint"st submit # push bottom..top, create/retarget PRs, update stack links
st submit --draft # open newly created PRs as drafts
st submit --upto # stop at current branch (omit upstack descendants)
st submit --no-pr # push branches only; skip GitHub PR managementFor multi-PR stacks, st submit appends an idempotent stack block to each PR description while keeping all of your own prose outside the markers untouched:
<!-- st:stack:start -->
**Stack:**
- #41 (`db-schema` β `main`)
- π **#42** (`user-store` β `db-schema`) *(this PR)*
- #43 (`user-api` β `user-store`)
<sub>Managed by `st`. Merge bottom-up.</sub>
<!-- st:stack:end -->Single-PR stacks stay completely clean (no stack block added unless one already exists).
st bottom # jump to db-schema (or st down / st checkout db-schema)
# ...edit schema.sql...
git add schema.sql
st modify # amends db-schema, then restacks user-store & user-api
st submit # force-pushes updated stack & keeps PRs in syncNeed a new commit instead of amending? Use st modify --commit -m "Handle null email". Want to collapse a messy branch back into one clean commit? Run st squash -m "Add users table".
st sync --submit # or shorthand: st sync -sIn one command, st:
- Fetches and fast-forwards
main. - Detects merged PRs β via Git ancestry, 3-way
git merge-treesquash-merge detection, and GitHub PR state. - Deletes
db-schema, re-parentsuser-storeontomain, and switchesHEADtouser-store. - Restacks
user-storeanduser-apionto the newmain. - Retargets PR #42's GitHub base from
db-schemaβmainbefore pushing, force-pushes the updated stack, and refreshes the stack links on #42 and #43.
st log # current stack only (zero network, shows trunk lag)
st log --all # all tracked stacks in the repo
st log --pr # add PR #number, draft, CI checks (β/β/β―), base mismatches
st status --pr # current branch details, commits, trunk lag, and PR infost is designed to be driven reliably by AI coding agents and CI/automation scripts β see docs/AGENT.md for the full contract (JSON schemas, error envelopes, idempotency).
-
Machine-readable everywhere: every command except
__completeandcompletion(plushelp/version) accepts--json. Errors emit structured JSON envelopes onstderrand keepstdoutclean. -
Stable exit codes:
Exit code JSON error.codeMeaning 0β Success 1error/pausedUsage, git, or precondition error 2conflictRebase stopped on a merge conflict ( st continue/st abort)3not_initializedRepo has not run st init4dirtyTracked uncommitted changes block the operation 5locked/locked_guardAdvisory repo lock is held by another stprocess70internalUnexpected internal error -
Current-stack scoping by default:
st log,st sync,st submit,st restack, andst doctordrift warnings scope to your current stack when on a tracked branch so parallel work in sibling stacks or othergit worktrees is never disturbed. Pass--allwhenever you want the whole forest. -
Safe with external
git worktrees:stshares.git/stacked/state.jsonacross worktrees, rebases clean dependent worktrees in place during cascades, skips dirty orgit worktree locked worktrees with a note, omits your own worktree path fromst logto keep output noise-free, and never creates or deletes worktrees on disk. -
Dry-run & Undo: preview mutations with
--dry-runoncreate,modify,restack,squash,onto,rename,delete,track --all,untrack,sync, andsubmit. Roll back the last mutation withst undo(preserves your working tree).
st stores all metadata in .git/stacked/state.json (written atomically via temp file + rename, guarded by an advisory lock):
{
"version": 1,
"trunk": "main",
"branches": {
"feat-auth": {
"name": "feat-auth",
"parent": "main",
"parentSHA": "a1b2c3d4..."
},
"feat-api": {
"name": "feat-api",
"parent": "feat-auth",
"parentSHA": "e5f6a7b8..."
}
}
}Each branch records parentSHA β the parent commit it was last rebased onto. When feat-auth changes, feat-api.parentSHA no longer matches feat-auth's tip, so st marks it (needs restack) and runs:
git rebase --onto <current tip of feat-auth> <feat-api.parentSHA> feat-apiThen it updates feat-api.parentSHA and walks upward in topological order. If a rebase hits a conflict, st exits 2 leaving the standard Git rebase paused β resolve the files, git add, and run st continue (or st abort to back out).
Flags may appear before or after positional arguments. Run st help <command> (or st <command> -h) for full flag details.
Every command below except __complete and completion (plus help/version) accepts --json; see docs/AGENT.md.
| Command | Aliases | Summary |
|---|---|---|
st init [--trunk <name>] |
Initialize stack tracking in this repo. | |
st log [--all] [--pr] |
ls |
Show the current stack tree (--all for all stacks, --pr for GitHub PR & CI status). |
st status [--pr] |
stat |
Show current branch, parent/children, commits (--json), trunk lag, and restack state. |
st doctor [--fix] [--all] |
validate |
Check stack metadata for problems and drift (--fix repairs metadata, --all checks all stacks). |
st guide |
Print the recommended stacked-diff workflow (handy for agents). |
| Command | Aliases | Summary |
|---|---|---|
st checkout [name] |
co |
Check out a tracked branch (or trunk), or list tracked branches with no arg. |
st up [n] |
u |
Move n levels up toward leaves (stops at branch points). |
st down [n] |
d |
Move n levels down toward trunk. |
st top |
t |
Jump to the leaf of the current stack. |
st bottom |
b |
Jump to the lowest branch above trunk. |
| Command | Aliases | Summary |
|---|---|---|
st create <name> [-m|--message <msg>] [-a|--all] [--dry-run] |
c |
Create and track a branch stacked on current (-a stages tracked edits; -m commits). |
st modify [-m|--message <msg>] [-a|--all] [--commit] [--dry-run] |
amend, m |
Amend (or --commit) staged changes (-a stages tracked edits) and restack upstack. |
st restack [--all] [--dry-run] |
r |
Rebase current branch and upstack onto their parents (--all for whole forest). |
st squash [-m|--message <msg>] [--dry-run] |
Collapse all commits on the current branch into one and restack upstack. | |
st onto <target> [--dry-run] |
move |
Re-parent the current branch (and its upstack) onto target. |
st rename [old] <new> [--dry-run] |
mv |
Rename a branch and update stack metadata & child parent pointers. |
st delete <name> [-f|--force] [--dry-run] |
rm |
Delete a merged/squash-merged branch (-f forces) and re-parent + restack children. |
st track [name] [--parent <branch>] [--all] [--dry-run] |
Start tracking an existing branch (or all untracked branches with --all). |
|
st untrack [name] [--dry-run] |
Stop tracking a branch and re-parent its children (keeps the git branch). |
| Command | Aliases | Summary |
|---|---|---|
st submit [--draft] [--no-pr] [--title <t>] [--body <b>] [--upto] [--all] [--remote <name>] [--dry-run] |
ss |
Push stack (--force-with-lease) and create/retarget/update GitHub PRs. |
st sync [-s|--submit] [--all] [--no-delete] [--no-fetch] [--remote <name>] [--dry-run] |
s |
Fetch & fast-forward trunk, prune merged branches, restack (-s pushes & updates PRs). |
| Command | Aliases | Summary |
|---|---|---|
st continue |
Resume a restack/onto/sync paused on a merge conflict. | |
st abort |
Abort an in-progress rebase and restore stack state. | |
st undo [--force] |
Revert the last stack-mutating command without touching your working tree. | |
st completion <bash|zsh|fish> |
Print a shell completion script (with live branch completion via st __complete). |
|
st help [<command>] / st version |
-h/-v |
Show help / print build & version info. |
- GitHub PR defaults:
st submitautomatically activates GitHub PR management whenever the remote is GitHub (including GitHub Enterprise) andghis onPATH. Single-commit branches default the PR title & body from that commit; multi-commit branches default the title from the oldest commit and bullet-list the subjects. Override the current branch's PR with--title/--body. - Offline sync:
st sync --no-fetchskips all network calls and prunes/restacks purely against your local trunk ref. - Shell completions: install once for live branch-name tab completion:
st completion zsh > "${fpath[1]}/_st" # zsh st completion bash > /etc/bash_completion.d/st # bash st completion fish > ~/.config/fish/completions/st.fish # fish
- Debugging git spawns: run
ST_DEBUG=1 st <cmd>to trace everygitinvocation and duration onstderr(stdout/--jsonstays untouched). - Waiting on locks: set
ST_LOCK_WAIT=10sto retry briefly on advisory lock contention instead of failing immediately with exit5.
The repo closes its own loop locally β make test-fast runs the pure fake-git engine suite in ~1s, and make ci runs version-pin checks, gofumpt, strict golangci-lint, go vet (+ Windows/Plan 9 cross-vet), -race tests, black-box e2e, and a merged coverage gate (β₯75% total, β₯50% per function).
See CONTRIBUTING.md for the add-a-command recipe and AGENTS.md for the architecture and constraints.