Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

git-clean-branches

Zero dependencies Node License: MIT Platform

Interactively clean up merged and stale local git branches. Zero dependencies.

Unlike git branch --merged | grep -v master | xargs git branch -d (Unix-only, no confirmation), this works on Windows and prompts before deleting.


Install

npm install -g git-clean-branches

Or without installing:

npx git-clean-branches

Usage

git-clean-branches                 # List all non-protected branches
git-clean-branches --merged        # Show merged branches, confirm before delete
git-clean-branches --stale 30      # Show branches not touched in 30+ days
git-clean-branches --merged --yes  # Delete merged branches without prompting
git-clean-branches --merged --dry-run  # Show what would be deleted

Example Output

git-clean-branches  main

  feature/user-auth                 Add JWT middleware         [merged] [3d]
  fix/login-redirect                Fix redirect after login   [merged] [7d]
  experiment/graphql                Initial GraphQL setup               [45d]
  wip/notifications                 WIP: push notifications             [62d]

  Delete all 4 branches listed above? [y/N/list]

Enter y to delete all, n to cancel, or list to confirm each one individually.


Protected Branches

These are never deleted regardless of flags:

  • main, master, trunk, develop
  • The currently checked-out branch
  • The base branch (auto-detected or set via --base)

Options

Flag Description
--merged Show/delete branches already merged into main
--stale <days> Show/delete branches not touched in N days
--base <branch> Override base branch (default: auto-detect main/master)
--force Use git branch -D (force delete unmerged branches)
--yes Skip confirmation prompt
--dry-run Show what would be deleted, don't delete

License

MIT


Keywords

git branch cleanup · delete merged branches · stale branches · prune branches · clean git branches · remove old branches · git housekeeping · merged branches · cross-platform · zero dependencies


Built to solve, shared to help — Rushabh Shah 🛠️✨

One of 40+ zero-dependency developer CLI tools — no node_modules, ever.