Skip to content

Add git cleanup: delete local branches that are merged or gone - #38

Merged
martyzz1 merged 1 commit into
masterfrom
feature/ENG-2110-git-cleanup
Nov 7, 2026
Merged

martyzz1 merged 1 commit into
masterfrom
feature/ENG-2110-git-cleanup

Conversation

@martyzz1

@martyzz1 martyzz1 commented Nov 7, 2026

Copy link
Copy Markdown
Collaborator

Why

Local branches pile up across worktrees once their PRs are merged. The gitclean zsh function people have been using cleans them up, but it hard-codes main and doesn't live with the rest of the gitfeatures commands.

What changes

New git cleanup command:

  • Runs git fetch --prune origin, then finds local branches that are either:
  • Never deletes masterBranch or a branch checked out in any worktree, and only deletes local branches; nothing on origin changes.
  • Lists each branch with the reason it qualifies and asks before deleting. --dry-run only lists, and --yes skips the question.

It also adds a git-cleanup console entry point, a scripts/git-cleanup wrapper, a README section with quick start and install mentions, and a CHANGELOG line.

Tests

tests/test_cleanup.py sets 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 that git cleanup deletes exactly the right three, and that --dry-run lists them but deletes nothing. pre-commit run --all-files and pytest (73 tests) pass. A dry run against a real checkout of this repo listed only the stale feature/… branches and skipped every branch checked out in a worktree.

🤖 Generated with Claude Code

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>
@martyzz1
martyzz1 merged commit 12523b0 into master Nov 7, 2026
12 checks passed
@martyzz1
martyzz1 deleted the feature/ENG-2110-git-cleanup branch November 7, 2026 13:42
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