Skip to content

docs: never merge with --delete-branch - #275

Open
joaodinissf wants to merge 1 commit into
docs/linking-mechanism-fixfrom
docs/no-delete-branch-flag
Open

docs: never merge with --delete-branch#275
joaodinissf wants to merge 1 commit into
docs/linking-mechanism-fixfrom
docs/no-delete-branch-flag

Conversation

@joaodinissf

@joaodinissf joaodinissf commented Jul 30, 2026

Copy link
Copy Markdown
Collaborator

gh pr merge --delete-branch closes stacked pull requests instead of letting GitHub retarget them.

This closed #247, which was based on #246's branch. It has since been recovered — restoring the deleted ref breaks the deadlock, and CLAUDE.md now carries the recipe alongside the rule.

Verified rather than inferred. Two structurally identical stacks in a scratch repository, same settings as here — rebase-merge only, delete_branch_on_merge on:

Base merged with Dependent PR
--rebase (repo setting deletes the branch) retargeted to main, still open
--rebase --delete-branch closed, conflicting, stuck on a deleted base

The control stayed retargeted and open throughout the second arm, so it is not a timing artefact.

The mechanism: GitHub's merge flow retargets dependants and then deletes. Deleting from the client pre-empts the retarget step.

Recovery works only in this order — a closed PR cannot be retargeted, and a PR whose base is missing cannot be reopened:

gh api -X POST repos/OWNER/REPO/git/refs -f ref=refs/heads/DELETED_BASE -f sha=MERGED_HEAD_SHA
gh pr reopen N
gh api -X PATCH repos/OWNER/REPO/pulls/N -f base=main
gh api -X DELETE repos/OWNER/REPO/git/refs/heads/DELETED_BASE

MERGED_HEAD_SHA is the merged PR's head.sha, which survives the branch deletion. This restores the original PR with its review history and author, which opening a replacement cannot do.

This pull request was published with assistance from Claude.

The repository already deletes merged branches, and letting it do so is what
preserves stacked pull requests: GitHub retargets any PR based on the merged
branch onto its base. Deleting the ref from the client pre-empts that step,
and GitHub closes the dependent PR instead — permanently, since a closed PR
cannot be reopened while its base is missing and cannot be retargeted while
it is closed.

This closed #247, which was stacked on #246. Verified in a scratch repository
with two identical stacks differing only in the delete method: the flagged one
left its dependent PR closed and stranded, the other retargeted cleanly.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@joaodinissf
joaodinissf force-pushed the docs/no-delete-branch-flag branch from aa87b8b to 4f6dfa1 Compare August 1, 2026 16:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant