Back to Projects

Problem Statement

In active development teams, feature, fix, and chore branches accumulate rapidly. Git doesn't automatically clean them up after a merge, and doing so manually is tedious and prone to error.

Warning

Accumulating hundreds of stale branches creates visual noise, hinders autocompletion, and causes confusion about the actual state of pending work.

Solution: Git-Cleaner

Git-Cleaner is an interactive CLI tool designed to maintain the hygiene of your Git repositories. It helps identify and safely remove stale branches by applying smart filters for author, date, and merge status.

Features

  • Interactive Mode
  • Easy-to-use CLI menu (no need to remember complex flags).

  • Test Mode (Dry-Run)
  • Visualize which branches would be deleted before touching anything.

  • Flexible Filters
  • By Author: Clean only your branches (TARGET_USERS) or everyone's EXCEPT certain users (EXCLUDE_USERS).
  • By Status: Filter only branches already merged into main/master or review all old ones.
  • Age: Target branches with inactivity (configurable, default 1 month).
  • Protection
  • List of protected branches that will never be deleted (e.g., main, dev).


    Installation

    The process is simple. First clone the repository and then install the dependencies.

    bash
    Cargando sintaxis...
    šŸ”’ BitSentry_Terminal
    Ln 5, Col 1UTF-8

    Configuration

    Before using it, create your configuration file based on the provided example.

    bash
    Cargando sintaxis...
    šŸ”’ BitSentry_Terminal
    Ln 1, Col 1UTF-8

    Edit the .env file with your preferences:

    VariableDescriptionExample
    TARGET_USERSList of authors to clean (separated by |)jdoe|asmith
    EXCLUDE_USERSUsers to exclude. Ignores TARGET_USERS if definedadmin|bot
    PROTECTED_BRANCHESBranches that will never be deletedmain,master,release
    GIT_PATHAbsolute path to the repo (optional)/Users/me/repo

    Usage

    Run the script directly with Node.js:

    bash
    Cargando sintaxis...
    šŸ”’ BitSentry_Terminal
    Ln 3, Col 1UTF-8

    The interactive assistant will guide you through two main steps:

    1. Select Mode

  • Test Mode
  • Lists candidate branches without deleting anything. (Recommended to start)

  • Shows author, date, and merge status.
  • Allows visual verification before acting.
  • Action Mode
  • Proceeds to delete selected branches (requires final confirmation).

    2. Select Filter

  • All stale branches
  • Applies date and author filters, regardless of whether Git knows they are merged.

  • Merged branches only
  • Additionally verifies if the branch exists in origin/main or origin/master.

    Important

    In Action Mode, the tool will always ask for an explicit final confirmation before executing git push origin :branch. It will never delete anything without your final "YES".

    Execution Example

    Here is how a typical run looks in your terminal:

    bash
    Cargando sintaxis...
    šŸ”’ BitSentry_Terminal
    Ln 10, Col 1UTF-8

    Security First

    Security is not an optional feature; it is the absolute priority of Git-Cleaner. We have designed every step to be non-destructive by default.

    Triple Layer Protection

  • 1.Smart Whitelists
  • The system strictly respects your PROTECTED_BRANCHES configuration. Branches like main, master, dev, or release/* are invisible to the deletion process. They will never be suggested.

  • 2.Visual Verification (Dry-Run)
  • "Test Mode" is the default. You can see a complete audit of:

  • Branch name
  • Original author
  • Date of last commit
  • Merge Status (Merged / Not Merged)
  • Nothing is deleted until you see it clearly.

  • 3.Explicit Confirmation ("Kill Switch")
  • Even in "Action Mode", the system pauses before executing the final command.

    Are you sure you want to delete these X branches? (y/n)

    Without your explicit final confirmation, the git push --delete command never runs.