Skip to content

CLI

Terminal window
gitsweep [options]

Run with no arguments, gitsweep finds the stale branches in the current repository, groups and prints them, asks you to confirm, and then deletes them. The current branch and the default branch are never candidates — see How it works.

Terminal window
# one-off, no install
npx gitsweep
# or install globally
npm i -g gitsweep
# or: pnpm add -g gitsweep

Requires Node.js ≥ 18 and git on your PATH.

FlagDescription
--dry-runList what would be deleted, then exit. Never deletes.
-y, --yesDelete without prompting for confirmation.
--mergedOnly consider branches merged into the default branch.
--goneOnly consider branches whose upstream is gone.
--main <branch>Override default-branch detection (e.g. --main develop).
-h, --helpShow help and exit.
-v, --versionShow the version and exit.

--merged and --gone are mutually exclusive — passing both prints an error and exits with code 2.

Prints the exact list a real run would delete, ends with Dry run: N branch(es) would be deleted., and exits 0 without touching any branch. The recommended first run.

Skips the [y/N] confirmation and deletes the candidates immediately. Useful in scripts and CI. All safety guarantees still apply — the current and default branches are never deleted, and merged branches still use the safe -d.

Restrict candidates to a single category. --merged keeps only branches merged into the default branch; --gone keeps only branches whose upstream is gone. The filter is applied to the raw facts, so --gone still catches a branch that happens to also be merged.

Override the default-branch detection when your trunk isn’t main/master or detection guesses wrong. The named branch becomes both the merge target and an excluded candidate.

CodeMeaning
0Success — nothing to do, a dry run, or branches were deleted.
2Not a git repository, a git command failed, or conflicting flags.

A clean run, an empty “nothing to sweep” result, and a dry run all exit 0. A run where one or more git branch deletes fail exits 2 after reporting which branches could not be removed.

Preview what would be swept without changing anything:

Terminal window
gitsweep --dry-run

Sweep only branches whose remote is gone, after pruning stale remotes:

Terminal window
git fetch --prune
gitsweep --gone

Clean up merged branches non-interactively (handy in scripts):

Terminal window
gitsweep --merged -y

Work against a repo whose default branch is develop, previewing first:

Terminal window
gitsweep --main develop --dry-run

Check the installed version:

Terminal window
gitsweep --version