A Bash utility to easily clean up your inactive Git local branches.
Inspired by the simplicity of tools like npkill
, it allows you to quickly list and delete branches that have become unnecessary, with advanced features like date-based sorting and age filtering of commits.
Here's how the branch list looks with the standard git command:
With gitclean, you get a more detailed and organized view of your branches, with useful information like last commit date and author:
gitclean makes it easy to clean up unused branches with a secure interactive interface:
- 🎯 Flexible Branch Selection: List/delete all branches or only those merged with a specific branch
- 📊 Table Display: Clear and organized branch information with metadata
- 🔄 Date Sorting: Sort branches by last commit date
- ⏰ Age Filtering: Filter branches based on their last commit age
- 🎨 Colored Interface: ANSI colors for better readability
- ✅ Interactive Confirmation: Safe deletion with confirmation prompt
- 💪 Force Mode: Option to delete non-merged branches
# List branches
gitclean --list-branches [main_branch] [--sort-by-date] [--older-than <days>]
# Delete branches
gitclean --prune-branches [main_branch] [--force] [--older-than <days>]
- Clone the repository
git clone https://github.com/nahtandev/gitclean.git
cd gitclean
- Make the tool executable
chmod +x bin/gitclean
- Install globally (optional)
sudo ln -s $(pwd)/bin/gitclean /usr/local/bin/gitclean
# List all branches
gitclean --list-branches
# List branches merged with main
gitclean --list-branches main
# Sort all branches by last commit date
gitclean --list-branches --sort-by-date
# Sort merged branches by last commit date
gitclean --list-branches main --sort-by-date
# Filter all branches by age (> 20 days)
gitclean --list-branches --older-than 20
# Filter merged branches by age (> 20 days)
gitclean --list-branches main --older-than 20
# Combine options
gitclean --list-branches main --sort-by-date --older-than 30
The table displays for each branch:
- 🌿 Branch name
- ⏱️ Last commit date
- 👤 Author
- 📊 Total commit count
- 💬 Last commit message
- 📅 Creation date
# Delete all branches (with confirmation)
gitclean --prune-branches
# Delete branches merged with main
gitclean --prune-branches main
# Delete old branches (> 20 days)
gitclean --prune-branches --older-than 20
# Delete old merged branches (> 20 days)
gitclean --prune-branches main --older-than 20
# Force deletion of all branches
gitclean --prune-branches --force
# Force deletion of merged branches
gitclean --prune-branches main --force
# Combine force and age
gitclean --prune-branches --force --older-than 30
--force
option allows deletion of non-merged branches.
gitclean/
├── bin/
│ └── gitclean # Main script
├── src/
│ ├── list_branches.sh # --list-branches command
│ ├── prune_branches.sh # --prune-branches command
│ └── utils.sh # Utility functions
├── tests/
│ └── test_list.sh # Tests
└── README.md
- GitHub: @nahtandev
- Specialized in web and backend development
- Passionate about productivity tool development
MIT License - see the LICENSE file for details.
This tool modifies your local Git repository. Make sure to:
- Back up important changes
- Understand which branches will be affected
- Be especially careful with the
--force
option