2026-07-05 11:34:18 +00:00
2026-07-01 10:21:58 +02:00
2026-07-01 10:08:24 +02:00
2026-07-01 10:26:52 +02:00
2026-07-01 08:28:14 +00:00

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

git clone <repository>
cd cleanupGoneBranches

go build -o cleanupGoneBranches

Or install directly:

go install

Usage

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:

git branch -d

which only deletes branches that Git considers safely merged.

If you want to force deletion, use:

cleanupGoneBranches --force

which uses:

git branch -D

Show Gone Branches Only

cleanupGoneBranches --show

Useful if you just want to inspect stale branches.


Delete Everything

cleanupGoneBranches --all

All gone branches are selected automatically, but you'll still be asked for confirmation before deletion.


Manual Git Equivalent

Run:

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.
S
Description
No description provided
Readme MIT 43 KiB
Languages
Go 100%