Repository navigation
Add git cleanup: delete local branches that are merged or gone - #38
Merged
Merged
Conversation
git cleanup fetches origin with --prune, then deletes local branches that are merged into origin/<their base branch> (recorded base, git's reflog, or masterBranch) or whose upstream has been deleted on origin, as GitHub does after a squash merge. It keeps masterBranch and any branch checked out in a worktree, only deletes local branches, lists what it will delete and why, and asks first. --dry-run only lists; --yes skips the question. 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.
Why
Local branches pile up across worktrees once their PRs are merged. The
gitcleanzsh function people have been using cleans them up, but it hard-codesmainand doesn't live with the rest of the gitfeatures commands.What changes
New
git cleanupcommand:git fetch --prune origin, then finds local branches that are either:origin/<their base branch>, using the base recorded inbranch.<name>.gitfeaturesBase, git's reflog, orgitfeatures.masterBranch(the base logic from Update branches in place and use each branch's own base (works in worktrees) #37); ormasterBranchor a branch checked out in any worktree, and only deletes local branches; nothing on origin changes.--dry-runonly lists, and--yesskips the question.It also adds a
git-cleanupconsole entry point, ascripts/git-cleanupwrapper, a README section with quick start and install mentions, and a CHANGELOG line.Tests
tests/test_cleanup.pysets up a branch merged into main, one deleted on origin, one unmerged, one merged only into a release branch (its recorded base), and one merged but checked out in a worktree. The tests check thatgit cleanupdeletes exactly the right three, and that--dry-runlists them but deletes nothing.pre-commit run --all-filesandpytest(73 tests) pass. A dry run against a real checkout of this repo listed only the stalefeature/…branches and skipped every branch checked out in a worktree.🤖 Generated with Claude Code