An interactive tool to safely and easily delete Git branches
git-branch-delete-ui.sh
is a bash script that provides an intuitive graphical interface to delete Git branches interactively. The script uses dialog
to create a user-friendly interface that allows you to select multiple branches and confirm their deletion before executing the action.
- π Automatic detection: Automatically identifies all available branches
- π‘οΈ Smart protection: Automatically excludes
main
,master
branches and the current branch - β Safety confirmation: Asks for confirmation before deleting selected branches
- π― Multiple selection: Allows selecting multiple branches to delete in a single operation
- π Informative messages: Provides clear feedback with success, warning, and error messages
- π Repository validation: Verifies that the current directory is a valid Git repository
The script requires dialog
for the graphical interface:
brew install dialog
sudo apt-get install dialog
sudo yum install dialog
- Download the script:
curl -O https://raw.githubusercontent.com/c4arl0s/git-branch-delete-ui/main/git-branch-delete-ui.sh
- Make the script executable:
chmod +x git-branch-delete-ui.sh
- Optional: Add to PATH
# Add to ~/.bashrc or ~/.zshrc
export PATH="$PATH:/path/to/your/script"
./git-branch-delete-ui.sh
- Navigate to your Git repository:
cd /path/to/your/repository
- Run the script:
./git-branch-delete-ui.sh
-
Select the branches:
- The script will display a list of available branches
- Use arrow keys to navigate
- Press space to select/deselect branches
- Press Tab to move between options
-
Confirm deletion:
- The script will ask for confirmation before deleting
- Select "Yes" to proceed or "No" to cancel

The script automatically excludes:
- The current branch (where you're working)
- The
main
branch - The
master
branch
- π΄ Errors: Displayed in red with timestamp
- π‘ Warnings: Displayed in yellow with timestamp
- π’ Success: Displayed in green when the operation is successful
- β Verifies that you're in a valid Git repository
- β Confirms that there are branches available to delete
- β
Asks for confirmation before executing
git branch -D
# Configuration variables
readonly CURRENT_BRANCHES_MSG='Current Branches to remove, select them:'
readonly DIDNT_SELECT_BRANCH_MSG='You did not select any branch'
# ... more variables
# Main functions
error() # Error handling
warning() # Warning handling
clean_branches() # Branch filtering
are_you_sure_msg() # User confirmation
# Main logic
# Repository validation β Branch retrieval β
# Filtering β User interface β Confirmation β Deletion
# Install dialog according to your operating system
brew install dialog # macOS
sudo apt install dialog # Ubuntu/Debian
# Make sure you're in a directory with a Git repository
cd /path/to/your/git/repository
git status # Verify it's a valid repo
- Verify you have local branches (not just remote ones)
- Make sure you're not on a branch without other local branches
- The script excludes
main
,master
and the current branch
This project is licensed under the MIT License. See the LICENSE file for more details.
Contributions are welcome. Please:
- Fork the project
- Create a feature branch (
git checkout -b feature/AmazingFeature
) - Commit your changes (
git commit -m 'Add some AmazingFeature'
) - Push to the branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
Carlos Santiago Cruz
- GitHub: @c4arl0s
- View more bash scripts
β Like this script? Give it a star!