# cleanupGoneBranches A small command-line utility written in Go that helps you clean up **local Git branches whose remote counterparts have already been deleted** ("gone" branches). Instead of manually finding and deleting stale branches, this tool: - Fetches and prunes your remote references - Detects local branches whose upstream no longer exists - Lets you interactively select which branches to delete - Protects your current branch from accidental deletion - Supports automatic cleanup and forced deletion ## Features - ✅ Runs `git fetch --prune` - ✅ Detects local branches with deleted remotes - ✅ Interactive branch selection - ✅ Range selection (`1,3-5`) - ✅ Select all (`all`) - ✅ Confirmation before deleting - ✅ Never deletes the currently checked-out branch - ✅ Optional forced deletion (`git branch -D`) - ✅ Show-only mode - ✅ Display equivalent manual Git commands --- ## Installation ### Build from source ```bash git clone cd cleanupGoneBranches go build -o cleanupGoneBranches ``` Or install directly: ```bash go install ``` --- ## Usage ```bash cleanupGoneBranches [options] ``` ### Options | Option | Description | |---------|-------------| | `--show` | Show gone branches only (don't delete anything) | | `--all` | Select all gone branches automatically (still asks for confirmation) | | `--force` | Use `git branch -D` instead of `git branch -d` | | `--info` | Show the equivalent manual Git commands | | `-h`, `--help` | Show help | --- ## Example ``` $ cleanupGoneBranches Git fetch with prune... Local branches with deleted remote (gone): 1) feature/login 2) bugfix/navbar 3) old-experiment Enter your selection, e.g. 1,3-5 or all. Leave blank to cancel. Selection: 1,3 The following branches will be deleted: - feature/login - old-experiment Really delete? (y/N): y Deleting branches... Deleted branch feature/login Deleted branch old-experiment Done. ``` --- ## Selection Syntax You can select branches using: | Input | Meaning | |--------|---------| | `1` | Delete branch #1 | | `1,4,7` | Delete branches 1, 4, and 7 | | `2-5` | Delete branches 2 through 5 | | `1,3-6` | Mixed selection | | `all` | Select every gone branch | Leaving the prompt empty cancels the operation. --- ## Safe by Default By default the tool uses: ```bash git branch -d ``` which only deletes branches that Git considers safely merged. If you want to force deletion, use: ```bash cleanupGoneBranches --force ``` which uses: ```bash git branch -D ``` --- ## Show Gone Branches Only ```bash cleanupGoneBranches --show ``` Useful if you just want to inspect stale branches. --- ## Delete Everything ```bash cleanupGoneBranches --all ``` All gone branches are selected automatically, but you'll still be asked for confirmation before deletion. --- ## Manual Git Equivalent Run: ```bash cleanupGoneBranches --info ``` to display the Git commands that perform the same operations manually. --- ## Requirements - Go 1.20+ (for building) - Git installed and available in your `PATH` - Must be executed inside a Git repository --- ## Notes - The currently checked-out branch is never deleted. - The tool automatically runs `git fetch --prune` before searching for gone branches. - Branches are always sorted alphabetically. - A confirmation prompt is shown before any deletion occurs.