Title: gh stack sync can fail force-with-lease push after fetching stack branches · Issue #118 · github/gh-stack · GitHub
Open Graph Title: gh stack sync can fail force-with-lease push after fetching stack branches · Issue #118 · github/gh-stack
X Title: gh stack sync can fail force-with-lease push after fetching stack branches · Issue #118 · github/gh-stack
Description: Summary gh stack sync can fetch and rebase a stack successfully, then fail during the final force push because the push uses a bare --force-with-lease with branch names instead of explicit destination refs and lease SHAs. This is most vi...
Open Graph Description: Summary gh stack sync can fetch and rebase a stack successfully, then fail during the final force push because the push uses a bare --force-with-lease with branch names instead of explicit destinat...
X Description: Summary gh stack sync can fetch and rebase a stack successfully, then fail during the final force push because the push uses a bare --force-with-lease with branch names instead of explicit destinat...
Opengraph URL: https://github.com/github/gh-stack/issues/118
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"gh stack sync can fail force-with-lease push after fetching stack branches","articleBody":"## Summary\n\n`gh stack sync` can fetch and rebase a stack successfully, then fail during the final force push because the push uses a bare `--force-with-lease` with branch names instead of explicit destination refs and lease SHAs.\n\nThis is most visible in checkouts where local branch upstream/tracking configuration is missing, stale, or does not line up with the branches that `gh stack sync` just fetched.\n\n## Problem\n\nToday the push shape is effectively:\n\n```console\ngit fetch origin b1\ngit rebase ...\ngit push origin --force-with-lease --atomic b1\n```\n\nThe failure happens at the final `git push`. Git has to infer both the destination branch and the expected lease value from local branch configuration / remote-tracking refs. If that inference does not match the refs that `gh stack sync` just fetched, the push can be rejected even though the command already refreshed the relevant stack branch.\n\n## Expected Behavior\n\nAfter `gh stack sync` fetches stack branches, the subsequent force push should use the fetched local tracking refs as the lease source.\n\nFor example:\n\n```console\ngit fetch origin b1\ngit rebase ...\ngit rev-parse --verify --quiet refs/remotes/origin/b1\ngit push origin --force-with-lease=refs/heads/b1:\u003cfetched-sha\u003e --atomic b1:refs/heads/b1\n```\n\nIf someone updates `b1` after the fetch, the push should still fail safely because `refs/heads/b1` no longer equals `\u003cfetched-sha\u003e`.\n\nIf `b1` did not have a local tracking ref, the lease should use an empty expected value, so creating the remote branch still fails if someone created it first.\n\n## Proposed Fix\n\nBuild explicit per-branch force-with-lease arguments:\n\n```console\n--force-with-lease=refs/heads/\u003cbranch\u003e:\u003ctracking-ref-sha\u003e\n```\n\nand push with explicit local-to-remote refspecs:\n\n```console\n\u003cbranch\u003e:refs/heads/\u003cbranch\u003e\n```\n\nThis avoids relying on Git's branch/upstream inference while preserving the stale-ref safety guarantee of `--force-with-lease`.\n\n## Related PR\nI have a fix in my fork for reference https://github.com/ravi-pplx/gh-stack/pull/1\n","author":{"url":"https://github.com/ravi-pplx","@type":"Person","name":"ravi-pplx"},"datePublished":"2026-06-07T23:44:56.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/118/gh-stack/issues/118"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:7bb3276a-7e2f-b7f6-0ec1-ee7ec1882045 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | DC88:4950B:673CEB1:909EC80:6A503DA1 |
| html-safe-nonce | 4f788f3ac46a9d58cd8bc9abac4d68bd089744a42a67c96d004e0fb647c951a0 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEQzg4OjQ5NTBCOjY3M0NFQjE6OTA5RUM4MDo2QTUwM0RBMSIsInZpc2l0b3JfaWQiOiI1Mjk0Mjg1MjMyNjkzODUzNjAxIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 92b26b987aed97cbb937e0604507fb94a517724a31ad8d4e3c6be2b69816d6a9 |
| hovercard-subject-tag | issue:4609103230 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/github/gh-stack/118/issue_layout |
| twitter:image | https://opengraph.githubassets.com/0ed7f2aa0ea3164a2d39d19b134cb728431c502750b6534c835a5b80c0ddc0c4/github/gh-stack/issues/118 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/0ed7f2aa0ea3164a2d39d19b134cb728431c502750b6534c835a5b80c0ddc0c4/github/gh-stack/issues/118 |
| og:image:alt | Summary gh stack sync can fetch and rebase a stack successfully, then fail during the final force push because the push uses a bare --force-with-lease with branch names instead of explicit destinat... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | ravi-pplx |
| hostname | github.com |
| expected-hostname | github.com |
| None | d6dc8294eb500fa36bbc57472d61fe87c522f9c3c1d64f70f4926f66a66a7efb |
| turbo-cache-control | no-preview |
| go-import | github.com/github/gh-stack git https://github.com/github/gh-stack.git |
| octolytics-dimension-user_id | 9919 |
| octolytics-dimension-user_login | github |
| octolytics-dimension-repository_id | 1151630728 |
| octolytics-dimension-repository_nwo | github/gh-stack |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 1151630728 |
| octolytics-dimension-repository_network_root_nwo | github/gh-stack |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | d90666eaf032b7eb8975a378efe38e37f4ebb96c |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width