Branch Sweeper
Find and delete stale local git branches safely: the ones whose upstream is gone, the ones already merged and, optionally, the ones with no recent commits, with a preview, a protected list and undo for the last 5 sweeps per repository.
What It Does
- Finds local branches whose upstream was deleted on the remote (
[gone], typical after a pull request is merged and its branch removed) and branches already merged into the default branch. Optionally also flags branches with no commits for a number of days.
- Shows every candidate with its reason in a multi-select preview, asks for confirmation, then deletes with
git branch -d (for merged branches that git branch -d refuses because HEAD is on another branch, Branch Sweeper verifies git merge-base --is-ancestor against the default branch and deletes with git branch -D).
- Never offers the current branch, the default branch or anything on your protected list (
main, master, develop, dev, development, staging, production, prod, trunk, stable, gh-pages and release/* by default).
- Branches with a gone upstream that git considers unmerged (for example squash-merged pull requests) are only force-deleted after a second, explicit confirmation.
- Records deleted branches and their commits for the last 5 sweeps per repository, so Branch Sweeper: Restore Last Sweep recreates them. Restore works until Git garbage collects the commits (about 2 weeks by default).
- Adds a Stale Branches view to the Source Control sidebar that lists what a sweep would offer.
Features (Free vs Pro)
| Feature |
Free |
Pro |
| Sweep the current repository: preview, protected list, confirmation, delete |
Included |
Included |
Optional git fetch --all --prune before sweeping (skipped silently offline) |
Included |
Included |
| Detect gone upstream, merged into the default branch, no commits for N days |
Included |
Included |
| Force delete of gone-upstream branches after a second confirmation |
Included |
Included |
| Restore Last Sweep |
Included |
Included |
| Stale Branches view in Source Control |
Current repository |
All repositories |
| Sweep every repository in the workspace |
Upgrade prompt |
Included |
Delete merged branches on the remote too (git push <remote> --delete) |
Upgrade prompt |
Included |
| Weekly reminder when many branches can be swept |
Not available |
Included |
Commands
branchSweeper.sweep (Branch Sweeper: Sweep Branches): Scans the current repository, previews candidates and deletes the ones you confirm.
branchSweeper.sweepAll (Branch Sweeper: Sweep All Repositories (Pro)): Same flow across every repository in the workspace with one combined preview.
branchSweeper.restoreLast (Branch Sweeper: Restore Last Sweep): Recreates the branches deleted by the last sweep at their recorded commits (keeps the last 5 sweeps per repository). Names that already exist are skipped. Restore works until Git garbage collects the commits (about 2 weeks by default).
branchSweeper.refresh (Branch Sweeper: Refresh): Rescans the Stale Branches view.
branch-sweeper.enterLicense (Branch Sweeper: Enter License Key): Activates a Pro license key in VS Code SecretStorage.
How Branches Are Chosen
A branch is offered when its upstream is gone, or when its tip is an ancestor of the default branch (the local branch or origin/<default>). The default branch comes from branchSweeper.defaultBranch, then origin/HEAD, then main, master or develop. If none can be found, merged detection is off and gone upstreams are still detected.
With branchSweeper.staleDays set above 0, a branch whose last commit is at least that many days old is also offered, with the reason "no commits for N days". Idle branches are not preselected in the preview. Git decides the deletion: an idle branch that is fully contained in its upstream is deleted, one with unpushed or unmerged work is refused and kept. Idle branches are never force-deleted, and never deleted on the remote.
Squash-merged branches are not ancestors of the default branch, so they are caught through their gone upstream. Git itself decides whether git branch -d may delete a branch: it checks the branch's upstream, or the checked out branch when there is none. For merged branches that git branch -d refuses when HEAD is on another branch, Branch Sweeper verifies ancestry with git merge-base --is-ancestor against the default branch (or refs/remotes/<remote>/<default>) before deleting with git branch -D using the same tip-commit guard; if git branch -D still fails, the branch is reported as kept with the Git error. Other branches git refuses are reported and kept (with a force-delete confirmation for gone-upstream branches).
Remote deletion (Pro) is offered only for branches that are merged into the default branch and whose remote branch is merged into the remote default branch, has the same name and commit as the local branch, and differs from the remote default tip. You pick which remote branches to delete from a multi-select list (none preselected) and confirm in a modal dialog. The push uses --force-with-lease with the commit you last fetched, so a remote branch that moved since then is left alone. Protected and default branches are never deleted on the remote. Restore Last Sweep does not bring back remote branches.
Settings
branchSweeper.fetchPrune (boolean, default true): Run git fetch --all --prune before sweeping. Failures such as being offline are ignored.
branchSweeper.defaultBranch (string, default ""): Branch used for the merged check. Empty detects it.
branchSweeper.protectedBranches (string[], default ["main", "master", "develop", "dev", "development", "staging", "production", "prod", "trunk", "stable", "gh-pages", "release/*"]): Names or globs that are never offered. * matches within one path level, ** across levels.
branchSweeper.staleDays (number, default 0): Also offer branches with no commits for at least this many days. 0 turns this off.
branchSweeper.reminderThreshold (number, default 10): Pro. Show a weekly reminder when more branches than this can be swept across your repositories. 0 turns it off.
branch-sweeper.apiBaseUrl (string, default ""): Override the licensing API base URL (must use https://, machine-scoped).
branch-sweeper.webBaseUrl (string, default ""): Override the web storefront base URL (must use https://, machine-scoped).
The reminder is checked while the extension is active, which happens once you open the Source Control view or run one of its commands. It never fetches from the network.
Privacy and Data Handling
| Data |
Where |
Retention |
| Branch names, commit hashes, repository paths |
Read from your repositories; the last 5 sweeps per repository are kept in VS Code workspace storage so they can be restored |
Until restored or rotated out after 5 newer sweeps |
git fetch and git push --delete traffic |
Your configured Git remotes, only when you sweep |
Not stored by us |
| License key, product ID, machine ID hash |
Sent to the licensing API (branch-sweeper.apiBaseUrl) on Pro activation and refresh |
Active license lifetime |
| Telemetry |
None. The extension sends no usage data |
Not applicable |
Nothing about your repositories is sent to us. Branch names only reach the Git remotes you configured, when you fetch or delete remote branches.
Offline Behaviour
- Scanning, previewing, deleting and restoring only use your local repository and work offline.
- With
branchSweeper.fetchPrune on, the fetch is attempted first and skipped when it fails or takes longer than 30 seconds. Gone upstreams are then detected from the last successful fetch.
- Paid licenses are verified offline using the bundled Ed25519 public key with a 14-day grace period.
Requirements
Git must be installed (Git 2.23 or newer is recommended for worktree branch exclusion) and the built-in Git extension enabled. Untrusted and virtual workspaces are not supported because Git can run hooks and configuration from the repository.
Pricing
Branch Sweeper is free to use. Pro adds multi-repository sweeps, remote branch deletion and the weekly reminder.
- Pro: $4/month or $36/year
- All Access (every Toolsmith Labs extension): $12/month or $99/year
View plans and buy. After purchase, sign in to your account to copy your license key, then run Branch Sweeper: Enter License Key.
Support
Report issues or request help at github.com/toolsmith-labs/support. For billing or license questions, email jashambaliya05@gmail.com.
| |