{"slug": "determining-if-your-branch-is-part-of-a-github-stacked-pr", "title": "Determining if your branch is part of a GitHub Stacked PR", "summary": "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.", "body_md": "Since the availability of [GitHub's Stacked PRs](https://github.github.com/gh-stack/) finally landing for repositories that use a Merge Queue, I've been \"kicking the tyres\" with some of my contributions to [Renovate](https://docs.renovatebot.com/).\n\nThey'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.\n\nI'd started wiring this into my zsh config, still using [Grml's zsh config](https://grml.org/zsh/) as a base, and found it was a bit awkward.\n\nI 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:\n\n```\n# in case you're working in a Git worktree\ngit_common_dir=\"$(git rev-parse --git-common-dir 2>/dev/null)\" || { REPLY=\"\"; return }\nstack_file=\"$git_common_dir/gh-stack\"\n\nposition=\"$(jq -r --arg b \"$(git branch --show-current)\" '\n .stacks[]\n | select(.branches[]?.branch == $b)\n | (.branches | map(.branch)) as $names\n | ($names | index($b)) as $idx\n | \"\\($idx + 1)/\\($names | length)\"\n' \"$stack_file\" 2>/dev/null | head -n1)\"\n\necho \"$position\"\n# outputs i.e. `x/y` or `` if not in a stack\n```\n\nI end up wiring this into my zsh prompt to show a `🥞 1/3`\n\nindicator like so:\n\nThis 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`\n\n, you'll show as still on a stack.\n\nHowever, [you can't run gh stack sync without being on a stacked branch](https://github.com/github/gh-stack/issues/483), so your cached data may be out-of-sync until that's fixed.", "url": "https://wpnews.pro/news/determining-if-your-branch-is-part-of-a-github-stacked-pr", "canonical_source": "https://www.jvt.me/posts/2026/08/26/zsh-stacked-pr/?utm_medium=rss&utm_source=rss", "published_at": "2026-08-26 14:41:41+00:00", "updated_at": "2026-08-26 15:13:07.142393+00:00", "lang": "en", "topics": ["developer-tools"], "entities": ["GitHub", "Renovate", "Claude Sonnet 5", "Grml", "gh-stack"], "alternates": {"html": "https://wpnews.pro/news/determining-if-your-branch-is-part-of-a-github-stacked-pr", "markdown": "https://wpnews.pro/news/determining-if-your-branch-is-part-of-a-github-stacked-pr.md", "text": "https://wpnews.pro/news/determining-if-your-branch-is-part-of-a-github-stacked-pr.txt", "jsonld": "https://wpnews.pro/news/determining-if-your-branch-is-part-of-a-github-stacked-pr.jsonld"}}