Repository navigation
Description
Describe the bug
gh stack rebase --no-trunk is documented as "Skip trunk — only rebase stack branches onto each other". When the branch below the stack's lowest open branch is merged, it still rebases that open branch onto the local trunk, then reports rebased locally (without trunk). The local trunk is often stale when it's checked out in another worktree, so the next gh stack push force-pushes an untouched bottom PR onto an outdated trunk.
Likely cause: in runRebase (cmd/rebase.go), --no-trunk only skips index 0 (if opts.noTrunk && startIdx < 1 { startIdx = 1 }), but s.Branches still holds merged branches. The merged predecessor sets needsOnto, and cascadeRebase falls back to trunkRef because no non-merged ancestor exists. Starting the range after s.FirstActiveBranchIndex(), with syncStackPRs called before the range is computed, fixes the repro below. I haven't run the test suite against that change.
Related: #491 (also a stale local trunk, on sync).
Affected command
gh stack rebase --no-trunk
gh-stack version
gh stack version 0.3.0
GitHub CLI version
gh version 2.103.3 (2026-10-26)
Operating system
macOS 26.1
Shell
zsh
Steps to reproduce
- Have a stack whose bottom branch's PR is merged, and whose trunk has moved on since.
- Commit on a middle branch.
- Run
gh stack rebase --no-trunk.
The script below does this offline in a temp directory (needs git, jq and gh-stack). Its jq line stands in for the GitHub API by recording b0's PR as merged.
Repro script
#!/usr/bin/env bash
set -euo pipefail
cd "$(mktemp -d)"
c() { echo "$1" > "$1.txt"; git add "$1.txt"; git commit -qm "$1"; }
git init -q --bare -b main origin.git
git clone -q origin.git primary 2>/dev/null && cd primary
git config user.email repro@example.com && git config user.name repro
c M1 && git push -q origin main
# Stack main <- b0 <- b1 <- b2 <- b3, in a linked worktree
git worktree add -q -b b0 ../stack main && cd ../stack
c B0; git checkout -qb b1; c B1; git checkout -qb b2; c B2; git checkout -qb b3; c B3
gh stack init b0 b1 b2 b3 >/dev/null
# b0's PR merges; trunk moves on to M2
cd ../primary
git merge -q --no-ff -m "Merge b0" b0 && c M2 && git push -q origin main
cd ../stack
# Stand-in for the GitHub API: record b0's PR as merged
F="$(git rev-parse --git-common-dir)/gh-stack"
jq --arg h "$(git rev-parse b0)" \
'.stacks[0].branches[0].pullRequest = {number: 1, url: "https://example.invalid/1", merged: true, mergedHead: $h}' \
"$F" > "$F.new" && mv "$F.new" "$F"
# Add a commit to b2 and cascade it upward without touching trunk
git checkout -q b2 && c FIX
echo "b1 sits on: $(git log -1 --format=%s b1~1)"
gh stack rebase --no-trunk
echo "b1 sits on: $(git log -1 --format=%s b1~1) (expected: B0)"Expected behavior
b1 stays on B0, and only b2 and b3 are rebased.
Actual behavior
b1 is rebased onto the local main (M2), and the command still reports it rebased without trunk.
Terminal output
b1 sits on: B0
Stack detected: (main) <- b0 <- b1 <- b2 <- b3
Rebasing branches in order, starting from b1 to b3
✓ Rebased b1 onto main (adjusted for merged PR)
✓ Rebased b2 onto b1 (adjusted for merged PR)
✓ Rebased b3 onto b2 (adjusted for merged PR)
Skipped 1 merged branch: b0
All branches in stack rebased locally (without trunk)
To push up your changes, run `gh stack push`
b1 sits on: M2 (expected: B0)
Preflight checks
- I searched the existing issues for duplicates.
- I ran
gh extension upgrade stackand reproduced this issue on the latest stable release.
🤖 Authored by Claude Code
Activity
nmussy commentedon Nov 23, 2026
Here is the patch mentioned above, against
v0.3.0. With it applied, the repro leavesb1onB0and rebases onlyb2andb3. I haven't run the test suite against it.syncStackPRsmoves up so the merged flags are current when the range is chosen. It now also runs before the "No branches to rebase" early return.🤖 Authored by Claude Code