← All tools

rosado-io/zsh-git-sweep

Popularity 65 Updated AI & Agents

Safely clean up local Git branches and worktrees after PRs, experiments, and AI-assisted coding sessions.

githubauto-collected

Installation

A directly usable install command is not verified yet. Check the project documentation or releases.

zsh-git-sweep

Oh My Zsh plugin that cleans up local Git branches, worktrees, and explicit remote branch sweeps after pull requests, experiments, and AI-assisted work sessions.

Why

When you use Git worktrees heavily, especially for AI coding sessions, local repositories quickly collect old branches and worktree directories. Some were already merged, some had their remote branch deleted, and some were simply left behind after an experiment.

git fetch -p prunes stale remote-tracking refs, but it does not delete your local branches. git branch -d can delete safe merged branches, but it fails when a branch is checked out in a Git worktree:

error: Cannot delete branch 'feature-x' checked out at '/path/to/worktree'

zsh-git-sweep handles that cleanup flow for you. It finds local branches that are already merged into your base branch, branches whose upstream is marked [gone], and optionally stale branches by age. It removes safe worktrees first, deletes the local branches, and prunes leftover worktree metadata. It also provides separate commands for intentionally deleting remote branches.

Safety

By default, gitsweep is intentionally conservative:

  • It targets local branches that are merged, whose upstream is [gone], or

that you explicitly include with --stale-days.

  • It skips the branch you are currently on.
  • It skips protected branch names such as main, master, trunk, develop,

and dev.

  • It removes worktrees without --force, so dirty worktrees are preserved.
  • It only deletes branches that are already merged into the base branch.

Use gitsweep --force only after reviewing the branch/worktree. Force mode runs git worktree remove -f and git branch -D, which can delete local worktree changes and unmerged commits.

By default, the base branch is detected from origin/HEAD, then common branch names like origin/main, origin/master, main, and master. Use --base to override it.

Remote cleanup is intentionally a separate command family because it mutates the remote repository with git push <remote --delete <branch:

  • gitsweep-remote-merged deletes remote branches that are already merged into