Repository navigation
Add prune-merged-branches.py - #54
Merged
Merged
Conversation
Deletes local branches whose work is already merged on GitHub, in one checkout or a folder of them: git branch -d when main contains the branch, and git branch -D for squash merges only when the merged PR's head is exactly the branch's tip. Branches checked out in a worktree, the default branch, wiki clones and non-GitHub checkouts are left alone. tests/test-prune-merged-branches.sh covers it offline in CI. Co-Authored-By: Claude Opus 5.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.
Adds
prune-merged-branches.py, which deletes local branches whose work is already merged on GitHub, in one checkout or in every checkout inside a folder.git branch -d.git branch -drefuses, is deleted withgit branch -Donly when a merged pull request's head commit is exactly the branch's tip. A branch that got commits after its PR was merged is kept.--dry-runlists what would be deleted without deleting anything. Every kept branch is listed with the reason. With no arguments it prints help.It reads origin's configured URL rather than
git remote get-url, so aurl.insteadOfrewrite doesn't hide that a checkout is on GitHub.tests/test-prune-merged-branches.shruns offline in CI: a local bare repository stands in for GitHub and a fakeghanswers the default-branch and merged-PR questions. It covers a normal merge, a squash merge from the exact tip, a squash-merged branch with a later commit, an unmerged branch, a branch checked out in a worktree, the default branch, a wiki clone, a non-GitHub checkout,--dry-run, a single checkout as the path, and no arguments.Testing (by Claude): the new tests pass and ShellCheck is clean. An earlier version deleted 19 merged branches across a folder of phpbbmodders checkouts and kept 38 with unmerged work; a dry run of this version on the same folder finds nothing left to delete and keeps the same 38.
Investigated and written by Claude on behalf of William Jacoby (bonelifer).
🤖 Generated with Claude Code