Skip to content

Anuar-boop/git-branch-clean

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 

Repository files navigation

git-branch-clean

A pure Bash utility for cleaning up Git branches. Find stale, merged, and squash-merged branches, then delete them interactively with built-in safety protections.

Features

  • List all branches with last commit date, author, and age
  • Find branches merged into main
  • Find branches with no activity in N days
  • Interactive deletion with selection
  • Protected branch patterns (never deletes main, master, dev, release/*)
  • Dry-run mode
  • Remote branch cleanup (prune stale tracking refs)
  • Squash-merged branch detection
  • Branch age histogram visualization

Installation

curl -o /usr/local/bin/git-branch-clean https://raw.githubusercontent.com/Anuar-boop/git-branch-clean/main/git_branch_clean.sh
chmod +x /usr/local/bin/git-branch-clean

Or clone and symlink:

git clone https://github.com/Anuar-boop/git-branch-clean.git
ln -s $(pwd)/git-branch-clean/git_branch_clean.sh /usr/local/bin/git-branch-clean

Usage

List all branches

git-branch-clean list
BRANCH                                   LAST COMMIT  AUTHOR               STATUS
---------------------------------------------------------------------------------
feature/auth                             2026-01-15   alice                 49d ago
bugfix/login                             2026-02-28   bob                   4d ago [protected]
main                                     2026-03-03   alice                 1d ago (current) [protected]

Find merged branches

git-branch-clean merged

Find stale branches (no activity in 30+ days)

git-branch-clean stale
git-branch-clean stale --days 60    # custom threshold

Interactive cleanup

git-branch-clean clean
git-branch-clean clean --dry-run    # preview without deleting
Select branches to delete:
  [1] feature/old-widget              (last: 2025-11-03)
  [2] bugfix/typo-fix                 (last: 2025-12-20)
  [3] experiment/new-api              (last: 2026-01-05)

Enter numbers to delete (comma-separated, 'all', or 'q' to quit): 1,3
  Deleted: feature/old-widget
  Deleted: experiment/new-api

Remote branch cleanup

git-branch-clean remote-clean
git-branch-clean remote-clean --remote upstream

Detect squash-merged branches

git-branch-clean squash-merged

Branch age histogram

git-branch-clean histogram
  < 1 week  ████████████                             3
  < 1 month ████████████████████                     5
  < 3 month ████████                                 2
  < 6 month ████████████████████████████████████████ 10
  < 1 year  ████████████                             3
  > 1 year  ████                                     1

  Total branches: 24

Options

Flag Description Default
-d, --days N Stale threshold in days 30
-m, --main NAME Main branch name main
-r, --remote NAME Remote name origin
-n, --dry-run Preview without changes off
-h, --help Show help -

Protected Patterns

These branch patterns are never deleted:

  • main, master
  • dev, develop
  • staging
  • release/*
  • hotfix/*

Requirements

  • Bash 4+
  • Git 2.x+

License

MIT

About

Pure Bash utility for Git branch cleanup. List, find stale/merged branches, interactive deletion, protected patterns, dry-run mode, squash-merged detection, and branch age histogram.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages