Delete a merged pull request's head branch automatically - #15
Merged
Conversation
The head branch of a merged pull request has no readers left: its commits are on main and its name is preserved in the pull request itself. Left alone they accumulate, and the branch list stops being a list of live work. Adds `.github/workflows/delete-merged-branch.yml`, which fires on `pull_request: closed` and deletes the head branch. The guards are the point: - **Merged only.** A pull request closed without merging keeps its branch, because the work on it has not landed anywhere. - **Same repository only.** A fork's branch is not ours to delete. - **Never the default branch**, and never `main`, `master`, `develop` or `release/*` — long-lived branches merge into main like any other, so the default-branch check alone does not cover them. - **Already deleted is a no-op**, not a failure, so deleting from the merge screen or re-running the workflow both exit cleanly. It uses the built-in `GITHUB_TOKEN` with `contents: write` — no personal access token, and no third-party action. GitHub's "Automatically delete head branches" repository setting does the same job, but it is a checkbox nobody can see from a clone; this keeps the behaviour in the tree where it is reviewable. The two are safe to run together — whichever gets there first wins and the other exits 0. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
github-actions
Bot
deleted the
claude/git-actions-branch-deletion-d4acd1
branch
August 21, 2026 05:52
arijitchhatui
added a commit
that referenced
this pull request
Aug 21, 2026
The "Automatically delete head branches" repository setting has been turned on, which does the same job as the workflow added in #15 — so the workflow is now redundant. The setting wins on what matters here: it cannot fail, because there is no runner, no token and no job to queue, and it costs no Actions minutes on every merge. The workflow's one advantage was being visible in the tree, and that is worth less than a mechanism with nothing to break. Removes `.github/workflows/delete-merged-branch.yml`. Behaviour is unchanged — merged head branches are still deleted automatically, and the setting leaves fork branches and closed-without-merge pull requests alone on its own. Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The head branch of a merged pull request has no readers left: its commits are on main and its name
is preserved in the pull request itself. Left alone they accumulate, and the branch list stops being
a list of live work.
Adds
.github/workflows/delete-merged-branch.yml, which fires onpull_request: closedand deletesthe head branch. The guards are the point:
has not landed anywhere.
main,master,developorrelease/*— long-livedbranches merge into main like any other, so the default-branch check alone does not cover them.
workflow both exit cleanly.
It uses the built-in
GITHUB_TOKENwithcontents: write— no personal access token, and nothird-party action.
GitHub's "Automatically delete head branches" repository setting does the same job, but it is a
checkbox nobody can see from a clone; this keeps the behaviour in the tree where it is reviewable.
The two are safe to run together — whichever gets there first wins and the other exits 0.