`gh stack checkout` reports "Local stack matches remote" without comparing local branch refs
Ninguém assumiu esta issue ainda.
Avaliação
- Dificuldade
- 3/5
- Tempo estimado
- 1-2 dias
- Facilidade para iniciantes
- 55/100
Direção de pesquisa
Comece pelo comando gh stack checkout e acompanhe a verificação que informa Local stack matches remote; execute a reprodução fornecida depois de mover uma referência de branch local com git reset --hard. Está concluído quando o comando compara os heads registrados ou remotos com as refs locais reais, avisa sobre divergências e indica a correção sugerida com git branch -f.
Escrita pelo modelo de indexação a partir do texto da issue.
Descrição
Summary
gh stack checkout reports ✓ Local stack matches remote when a local branch has diverged from its remote counterpart. It appears to compare its recorded state against the remote, and never against the actual local branch refs — so a local branch that has moved is invisible to the check.
$ git rev-parse --short=10 stack-b-two # local
df863cea57
$ git rev-parse --short=10 origin/stack-b-two # remote, one commit ahead
41fd74d3ae
$ gh stack checkout 6
✓ Local stack matches remote — switching to branch (stack #6)
ℹ Already on stack-b-two
$ gh stack view --short # no warning, no ⚠ Needs rebase
Stack #6
» stack-b-two ○ #5 (current)
├ stack-b-one ○ #4
└ main
The extension's own state file held the correct value the whole time:
$ jq -r '.stacks[].branches[] | select(.branch=="stack-b-two") | .head' .git/gh-stack
41fd74d3ae... # matches the remote; the local ref is what diverged
So this is not stale metadata. Recorded state and remote agreed, the local ref disagreed with both, and nothing compared against it.
Why this matters
This is the reassurance a user sees immediately before #380 destroys their work. In that state gh stack push rewinds the remote branch and the commits become unreachable — and if the branch loses its only commit, GitHub auto-closes the PR with no files. The sequence is:
gh stack checkout <n> -> "✓ Local stack matches remote"
gh stack push -> "✓ Pushed N branches" (remote commits gone, PR closed)
Fixing #380 addresses the destruction. Fixing this addresses the false confidence that leads someone to run the command in the first place.
How a local branch gets behind
Anything not mediated by the extension. A plain git fetch after a colleague pushes; CI committing to the PR head branch (the trigger in #380); or building a change in a git worktree and pushing it with git push origin <scratch-ref>:<pr-branch>, which moves the remote and leaves the local branch untouched.
Reproduction
Against a stack whose branches are in sync:
git switch <top-branch>
git reset --hard HEAD~1 # simulate the local branch falling behind
gh stack checkout <stack-number> # -> "✓ Local stack matches remote"
gh stack view --short # -> no warning
Public repo with two stacks set up for this: https://github.com/xn/gh-stack-repro
Expected
Compare recorded/remote heads against the actual local branch refs. On divergence, say so and name the fix (git branch -f <b> origin/<b>), rather than reporting a match.
A gh stack status / gh stack doctor surfacing per-branch local-vs-remote drift would cover the general case, since plain git will always be able to desync the extension's state.
Environment
gh2.97.0gh-stackv0.1.0- git 2.50.1
- macOS 26.4.1, darwin/arm64
Related
- #380 — the data loss this false reassurance leads into.
- #193 — handling rebases performed outside
gh stack; same general gap (external git operations invisible to the extension).
- Linguagem predominante
- Go
- Estrelas
- 1.5k
- Forks
- 73
- Merge médio
- 1d 8h
- PRs com merge (30d)
- 7
Guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Mais de github/gh-stack
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 85/100
-
Dificuldade 1/5 Menos de uma hora Facilidade para iniciantes 92/100
-
feature request topic: cli - general
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 68/100
-
feature request topic: auto-merge
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 68/100
-
bug topic: docs
Dificuldade 1/5 Menos de uma hora Facilidade para iniciantes 68/100
Todas as issues de github/gh-stack
Issues semelhantes
-
textual definition
Dificuldade 1/5 Menos de uma hora Facilidade para iniciantes 90/100
geneontology/go-ontology#32653 ·
-
Dificuldade 1/5 Menos de uma hora Facilidade para iniciantes 75/100
-
needs design
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 75/100
-
Priority/High ready-for-agent Severity/Major Type/Bug
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 75/100
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 70/100