Git Branch Cleaner
A VS Code extension that scans your local and remote Git branches, identifies merged and stale branches, and lets you safely delete them through an interactive UI.
Features
Local Branch Cleanup
- Merged branch detection — finds branches already merged into your current HEAD
- Stale branch detection — flags branches with no commits in the last N days (configurable)
- Protected branch filtering — never suggests deleting
main, master, dev, develop, staging, production, or your custom protected branches
- Unpushed commit guard — skips branches with local commits not yet pushed to a remote
- Interactive QuickPick UI — checkbox-style multi-select with branch status details
- Safe delete by default — uses
git branch -d (refuses to delete unmerged branches)
- Auto-fetch before scan — optionally runs
git fetch --prune to keep branch state fresh
Remote Branch Cleanup (new in v2.1)
- Remote branch scanning — lists all branches on your remote (e.g.
origin) after a fresh fetch
- Recent activity guard — branches with commits within the stale threshold are flagged as
⚡ Recently active and blocked from deletion, protecting work by teammates
- Merged-into-default-branch check — detects branches merged into
main/master on the remote
- Author visibility — shows who last committed to each remote branch
- Post-local-deletion prompt — after cleaning local branches, you're asked if you'd also like to clean remote branches
Commands
Open the Command Palette (Cmd+Shift+P / Ctrl+Shift+P) and run:
| Command |
Description |
Git Branch Cleaner: Scan Branches |
Interactive scan — pick which local branches to delete |
Git Branch Cleaner: Clean Branches (Auto-select Safe) |
Auto-selects all safe-to-delete local branches |
Git Branch Cleaner: Clean Remote Branches |
Fetch, scan, and delete stale/merged remote branches |
Typical Workflow
- Run Scan Branches or Clean Branches to clean up your local branches
- After deletion, a prompt appears: "Would you also like to clean up remote branches?"
- Click Yes, Scan Remote — the extension fetches the latest remote state and shows you which remote branches are safe to delete
- Or run Clean Remote Branches directly at any time to jump straight to remote cleanup
Remote Branch Safety
When scanning remote branches, a branch is only considered safe to delete if all of the following are true:
| Check |
Description |
| ✅ Not protected |
Not in the built-in or user-configured protected list |
| ✅ No recent activity |
No commits within the stale threshold (default: 30 days) |
| ✅ Merged or stale |
Either merged into the remote default branch, or inactive past the threshold |
Branches with recent activity are shown in the picker with a ⚡ Recently active label and cannot be selected, protecting your teammates' in-progress work.
Settings
| Setting |
Default |
Description |
gitBranchCleaner.protectedBranches |
[] |
Additional branches to protect (added to built-in defaults) |
gitBranchCleaner.staleDaysThreshold |
30 |
Days of inactivity before a branch is considered stale |
gitBranchCleaner.autoFetchBeforeScan |
true |
Run git fetch --prune before scanning local branches |
gitBranchCleaner.defaultRemote |
"origin" |
Default remote name for remote branch operations |
Example settings.json
{
"gitBranchCleaner.protectedBranches": ["hotfix", "release/v2"],
"gitBranchCleaner.staleDaysThreshold": 60,
"gitBranchCleaner.autoFetchBeforeScan": false,
"gitBranchCleaner.defaultRemote": "origin"
}
Safety Rules
Local branches — never suggested for deletion if:
- The currently checked-out branch
- A protected branch (built-in or user-configured)
- Has unpushed local commits
- Active with no merge or staleness issues
Remote branches — never suggested for deletion if:
- A protected branch (built-in or user-configured)
- Has commits within the stale threshold (recent activity by anyone)
- Active with no merge or staleness issues
Built-in Protected Branches
The following branches are always protected from both local and remote deletion:
main, master, dev, develop, staging, production, release
Project Structure
src/
├── extension.ts # Entry point — activates extension, registers all 3 commands
├── git.ts # Low-level Git command executor (child_process wrappers)
├── branchScanner.ts # Branch analysis engine (local + remote scanning)
├── ui.ts # VS Code UI layer (QuickPick, dialogs, notifications, prompts)
├── config.ts # Reads VS Code settings
└── types.ts # Shared TypeScript interfaces (BranchInfo, RemoteBranchInfo, etc.)
Development
# Install dependencies
npm install
# Compile TypeScript
npm run compile
# Watch mode (auto-recompile on save)
npm run watch
# Package as VSIX
npm run package
# Press F5 in VS Code to launch the Extension Development Host
License
MIT