cd /news/developer-tools/determining-if-your-branch-is-part-o… · home topics developer-tools article
[ARTICLE · art-111921] src=jvt.me ↗ pub= topic=developer-tools verified=true sentiment=· neutral

Determining if your branch is part of a GitHub Stacked PR

A developer shares a zsh script that uses jq to parse GitHub's gh-stack metadata file and display a branch's position in a stacked PR (e.g., 🥞 1/3), noting that the data can become stale until `gh stack sync` is run, which is currently blocked by a GitHub issue.

read1 min views1 publishedAug 26, 2026

Since the availability of GitHub's Stacked PRs finally landing for repositories that use a Merge Queue, I've been "kicking the tyres" with some of my contributions to Renovate.

They're working mostly well so far, but I'm finding it a bit annoying trying to remember if I'm on a branch that's part of a stack.

I'd started wiring this into my zsh config, still using Grml's zsh config as a base, and found it was a bit awkward.

I decided to outsource it to Claude Sonnet 5 - cause I guess that's the sort of person I am now? 😅 - and it came out with this:

git_common_dir="$(git rev-parse --git-common-dir 2>/dev/null)" || { REPLY=""; return }
stack_file="$git_common_dir/gh-stack"

position="$(jq -r --arg b "$(git branch --show-current)" '
 .stacks[]
 | select(.branches[]?.branch == $b)
 | (.branches | map(.branch)) as $names
 | ($names | index($b)) as $idx
 | "\($idx + 1)/\($names | length)"
' "$stack_file" 2>/dev/null | head -n1)"

echo "$position"

I end up wiring this into my zsh prompt to show a 🥞 1/3

indicator like so:

This works quite nicely, but I've found that it doesn't always stay in sync with GitHub. If a branch has been merged, but you've not yet run gh stack sync

, you'll show as still on a stack.

However, you can't run gh stack sync without being on a stacked branch, so your cached data may be out-of-sync until that's fixed.

── more in #developer-tools 4 stories · sorted by recency
── more on @github 3 stories trending now
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain — perfect for shipping the agent you just read about.

$git push zahid main
Live at https://your-agent.zahid.host
Get free account → Pricing
from €0/mo · no card required
LIVE [news/determining-if-your-…] indexed:0 read:1min 2026-08-26 ·