The ghouls can help you.
-
Command names have changed:
prunePullRequestsβremotepruneLocalBranchesβlocal
If you have scripts using the old commands, please update them to use the new shorter names.
pnpm add -g ghouls
Ghouls uses GitHub CLI authentication. Make sure you have the GitHub CLI (gh) installed and authenticated:
# Authenticate with GitHub CLI
gh auth loginThat's it! Ghouls will automatically use your existing GitHub CLI authentication.
If you don't have GitHub CLI installed, here are the installation instructions for all platforms:
# Using winget (recommended)
winget install --id GitHub.cli
# Using Chocolatey
choco install gh
# Using Scoop
scoop install gh# Using Homebrew (recommended)
brew install gh
# Using MacPorts
sudo port install gh
# Using Conda
conda install gh --channel conda-forge# Add GitHub CLI repository
curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null
sudo apt update
sudo apt install ghsudo dnf install ghsudo pacman -S github-clisudo zypper install ghFor other platforms and more installation options, visit: https://cli.github.com/
Safely deletes remote branches that have been merged via pull requests.
Run from within a git repository (auto-detects repo):
ghouls remote --dry-runThe auto-detection feature works with both github.com and GitHub Enterprise repositories, automatically detecting the repository owner/name from the remote URL.
Or specify a repository explicitly:
ghouls remote --dry-run myorg/myrepo$ ghouls remote myorg/myrepo
#1871 - Deleting remote: heads/fix/fe-nits
#1821 - Deleting remote: heads/fix/collaborator-search
#1799 - Deleting remote: heads/fix-yarn-for-1.24
#1758 - Skipping remote: heads/ml/search-polish (mismatched refs)
...
Safely deletes local branches that have been merged via pull requests. This command includes comprehensive safety checks to protect important branches and work in progress.
Run from within a git repository (auto-detects repo):
ghouls local --dry-runOr specify a repository explicitly:
ghouls local --dry-run myorg/myrepoThe local command includes several safety checks to prevent accidental deletion of important branches:
- Current branch protection: Never deletes the currently checked out branch
- Protected branch names: Automatically protects
main,master,develop,dev,staging,production, andprodbranches - Release and hotfix branch protection: Automatically protects release branches (
release/*,release-*) and hotfix branches (hotfix/*) - SHA verification: Only deletes branches where the local SHA matches the pull request head SHA
- Merge verification: Only considers pull requests that were actually merged (not just closed)
- Unpushed commits protection: Skips branches that have unpushed commits
- Dry-run mode: Use
--dry-runto see what would be deleted without making changes
$ ghouls local --dry-run
Scanning for local branches that can be safely deleted...
Found 15 local branches
Fetching merged pull requests from GitHub...
Found 42 merged pull requests
Branch Analysis:
Safe to delete: 3
Unsafe to delete: 12
Skipping unsafe branches:
- main (protected branch)
- feature/wip-work (2 unpushed commits)
- fix/critical-bug (current branch)
- hotfix/emergency (SHA mismatch with PR head)
Would delete 3 branches:
[DRY RUN] Would delete: feature/user-auth (#123)
[DRY RUN] Would delete: fix/typo-fix (#124)
[DRY RUN] Would delete: refactor/cleanup (#125)
Summary:
Would delete: 3 branches
Skipped (unsafe): 12
The all command combines both remote and local branch cleanup in a single operation, running them in sequence for maximum efficiency.
Run from within a git repository (auto-detects repo):
ghouls all --dry-runOr specify a repository explicitly:
ghouls all --dry-run myorg/myrepoThe command executes in two phases:
- Remote cleanup: Deletes merged remote branches first
- Local cleanup: Then deletes corresponding local branches
Even if one phase encounters errors, the command will continue with the next phase to ensure maximum cleanup.
$ ghouls all
π Starting combined branch cleanup...
=== Phase 1: Remote Branch Cleanup ===
Scanning for remote branches that can be safely deleted...
Found 5 branches that can be deleted.
Deleted: heads/feature/old-feature (PR #101)
Deleted: heads/fix/bug-123 (PR #102)
...
=== Phase 2: Local Branch Cleanup ===
Scanning for local branches that can be safely deleted...
Found 8 local branches
Branch Analysis:
Safe to delete: 3
Unsafe to delete: 5
Deleted: feature/old-feature (#101)
Deleted: fix/bug-123 (#102)
...
=== Combined Cleanup Summary ===
Remote cleanup: β
Success
Local cleanup: β
Success
β
All cleanup operations completed successfully!
The project uses Vitest for comprehensive unit testing.
pnpm testpnpm test:watchpnpm test:coverageThe test suite includes comprehensive unit tests covering all core functionality, utilities, and edge cases.
