Typical Workflows
This guide covers the most common workflows for day-to-day use of Stacked PRs, from the standard flow to advanced patterns.
Standard Workflow
Section titled “Standard Workflow”The basic flow: initialize a stack, add branches for each logical unit of work, commit, push, iterate on review feedback, and merge.
# 1. Start a stack (creates and checks out the first branch)gh stack init
# 2. Work on the first layer# ... write code, make commits ...
# 3. Add the next layergh stack add api-routes# ... write code, make commits ...
# 4. Push everything and create Stacked PRsgh stack submit
# 5. Reviewer requests changes on the first PRgh stack bottom# ... make changes, commit ...
# 6. Rebase the rest of the stack on top of your fixgh stack rebase
# 7. Push the updated branchesgh stack push
# 8. Sync upstream changes as PRs get mergedgh stack syncAbbreviated Workflow
Section titled “Abbreviated Workflow”For speed, use a branch prefix with --numbered and the -Am flags to fold staging, committing, and branch creation into a single command. Branch names are auto-generated as prefix/01, prefix/02, etc.
# Alias `gh stack` as `gs` for easier usegh stack alias
# 1. Start a stack with numbered branchesgs init -p feat --numbered# → creates feat/01 and checks it out
# 2. Write code for the first layer# ... write code ...
# 3. Stage and commit on the current branchgs add -Am "Auth middleware"# → feat/01 has no commits yet, so the commit lands here
# 4. Write code for the next layer# ... write code ...
# 5. Create the next branch and commitgs add -Am "API routes"# → feat/01 already has commits, so feat/02 is created
# 6. Keep going# ... write code ...gs add -Am "Frontend components"# → creates feat/03
# 7. Push everything and create PRsgs submitEach gs add -Am "..." stages all files, commits, and (if the current branch already has commits) creates a new branch — no separate git add or git commit needed.
Making Mid-Stack Changes
Section titled “Making Mid-Stack Changes”When you’re working on a higher layer and realize you need to change something lower in the stack — don’t hack around it at the current layer. Navigate down, make the change where it belongs, and rebase.
# You're on feat/frontend but need an API change
# 1. Navigate to the API branchgh stack down# or: gh stack checkout api-routes
# 2. Make the change where it belongsgit add users_api.gogit commit -m "Add get-user endpoint"
# 3. Rebase everything above to pick up the changegh stack rebase --upstack
# 4. Navigate back to where you were workinggh stack topThis keeps each branch focused on one concern and avoids muddying the diff for reviewers.
Responding to Review Feedback
Section titled “Responding to Review Feedback”When a reviewer requests changes on a PR mid-stack:
# 1. Navigate to the branch that needs changesgh stack checkout auth-middleware# or: gh stack bottom, gh stack down, etc.
# 2. Make the fixesgit add .git commit -m "Address review feedback"
# 3. Cascade the changes through the rest of the stackgh stack rebase
# 4. Push the updated stackgh stack pushThe rebase ensures all branches above the changed one pick up the fixes. gh stack push uses --force-with-lease to safely update the rebased branches.
Syncing After Merges
Section titled “Syncing After Merges”When a PR at the bottom of the stack is merged on GitHub, use gh stack sync to update your local state:
gh stack syncThis command:
- Fetches the latest changes from the remote
- Fast-forwards the trunk branch
- Rebases all remaining stack branches onto the updated trunk
- Pushes the updated branches
- Syncs PR state from GitHub
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.
Structuring Your Stack
Section titled “Structuring Your Stack”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.
Dependency order
Section titled “Dependency order”Plan your layers before writing code. Foundational changes go in lower branches, dependent changes go higher:
┌── tests ← integration tests for the full stack ┌── frontend-ui ← UI components that call the APIs ┌── api-endpoints ← API routes that use the models ┌── data-models ← shared types, database schemamain (trunk)When to create a new branch
Section titled “When to create a new branch”Create a new branch (gh stack add) when you’re starting a different concern:
- Switching from backend to frontend work
- Moving from core logic to tests or documentation
- The next changes have a different reviewer audience
- The current branch is already large enough to review
One stack, one effort
Section titled “One stack, one effort”All branches in a stack should be part of the same feature or project. If you need to work on something unrelated, start a separate stack with gh stack init or switch to an existing one with gh stack checkout.
Restructuring a Stack
Section titled “Restructuring a Stack”When you need to remove a branch, reorder branches, or rename branches, tear down the stack and rebuild it:
# 1. Remove the stack on GitHub and locallygh stack unstack
# 2. Make structural changesgit branch -m old-branch-1 new-branch-1 # rename a branchgit branch -D branch-3 # delete a branch
# 3. Re-create the stack with the new ordergh stack init --adopt new-branch-1 branch-2 branch-4
# 4. Push and sync the new stackgh stack submitThe unstack command deletes the stack on GitHub first, then removes local tracking. Your branches and PRs are not affected — only the stack relationship is removed. After init --adopt, any existing open PRs are automatically re-associated with the new stack.
Using AI Agents with Stacks
Section titled “Using AI Agents with Stacks”AI coding agents (like GitHub Copilot) can create and manage Stacked PRs on your behalf. Install the gh-stack skill to give them the context they need:
npx skills add github/gh-stackWith the skill installed, your agent can:
- Plan stack structure based on the work being done
- Create branches and commit changes in the right layers
- Navigate between branches to make mid-stack changes
- Push branches and create Stacked PRs
- Rebase after making changes to lower layers