Clean Branches Plugin for Oh My Zsh
October 22, 2025 ยท View on GitHub
A powerful, unified, and interactive branch cleanup tool for Zsh.
This plugin provides a single command, gprune, to find all local Git branches that are safe to delete, including:
- [stale]: Branches whose remote counterpart has been deleted.
- [merged]: Branches that have already been fully merged into your main branch (
mainormaster). - [WIP - unmerged]: Local-only branches that were never pushed and are not merged. (Use with caution!)
It uses fzf to provide a beautiful interactive UI, allowing you to easily select and delete multiple branches at once.
Prerequisites
Installation
-
Clone this repository into your Oh My Zsh custom plugins directory:
git clone https://github.com/wu9o/ohmyzsh-cleanbranches.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/cleanbranches -
Add the plugin to the list of plugins in your
~/.zshrcfile:plugins=( # other plugins... cleanbranches ) -
Restart your terminal or source your
~/.zshrcfile:source ~/.zshrc
Usage
Navigate to any Git repository and run the command:
gprune
An interactive fzf window will open, listing all deletable branches with their status.
- Use
TABto select one or more branches. - Press
Enterto confirm your selection. - A final confirmation prompt will appear before deletion.
How it Works
The gprune command performs the following steps:
- Fetches the latest remote state using
git fetch --prune. - Identifies your main branch (
mainormaster). - Finds branches in three categories:
- stale: Compares local branches with remote ones that are "gone".
- merged: Uses
git branch --mergedto find branches whose work is already in the main branch. This includes local-only branches that were created and then merged. - WIP - unmerged: Finds local-only branches that are not merged. Deleting these may result in permanent data loss.
- Presents a unique, tagged list of these branches for you to choose from.