Safely deletes local branches with no upstream and no un-pushed commits
Shell
191
47 commits
updated Jun 19, 2026
Github CLI extension
Safely delete local branches that have no remotes and no hanging changes.
The extension uses git branch -d to delete the local branches, hence it will not delete branches with un-pushed changes
unless using --force flag.
The extension supports single or multiple upstream.
gh extension install davidraviv/gh-clean-branches
Execute it inside a git repo folder:
gh clean-branches [--dry-run] [--force] [--verbose] [--worktrees]
--dry-run See the list of branches and worktrees to be deleted before actually deleting them.--force Uses git branch -D forcing a branch to be deleted regardless if upstream branches have local changes. Also force-removes worktrees that have uncommitted changes. Use carefully!--verbose Print all log statements.--worktrees Also remove local worktrees whose remote branch has been deleted, then delete their local branch. Worktrees in detached HEAD state (no branch) are removed as well. Without this flag, worktree cleanup is skipped and existing behaviour is unchanged.main) and pull changes (needed if we want to delete the current branch)--verbose flag)--verbose flag)--worktrees) Lists orphaned worktrees (remote branch gone or detached HEAD) and removes them--dry-run)The extension depends on:
Shell
100.0%
Safely deletes local branches with no upstream and no un-pushed commits
Shell
191
47 commits
updated Jun 19, 2026
Github CLI extension
Safely delete local branches that have no remotes and no hanging changes.
The extension uses git branch -d to delete the local branches, hence it will not delete branches with un-pushed changes
unless using --force flag.
The extension supports single or multiple upstream.
gh extension install davidraviv/gh-clean-branches
Execute it inside a git repo folder:
gh clean-branches [--dry-run] [--force] [--verbose] [--worktrees]
--dry-run See the list of branches and worktrees to be deleted before actually deleting them.--force Uses git branch -D forcing a branch to be deleted regardless if upstream branches have local changes. Also force-removes worktrees that have uncommitted changes. Use carefully!--verbose Print all log statements.--worktrees Also remove local worktrees whose remote branch has been deleted, then delete their local branch. Worktrees in detached HEAD state (no branch) are removed as well. Without this flag, worktree cleanup is skipped and existing behaviour is unchanged.main) and pull changes (needed if we want to delete the current branch)--verbose flag)--verbose flag)--worktrees) Lists orphaned worktrees (remote branch gone or detached HEAD) and removes them--dry-run)The extension depends on:
Shell
100.0%