Skip to content

nahtandev/gitclean

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🧹 gitclean

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.

🎬 Demo

🌿 Standard Git Branch

Here's how the branch list looks with the standard git command:

Git Branch Standard

📊 Branch Listing with gitclean

With gitclean, you get a more detailed and organized view of your branches, with useful information like last commit date and author:

Gitclean List

🧹 Branch Cleanup

gitclean makes it easy to clean up unused branches with a secure interactive interface:

Gitclean Prune

Gitclean Prune

Gitclean Prune

📌 Key Features

  • 🎯 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

⚡ Quick Usage

# List branches
gitclean --list-branches [main_branch] [--sort-by-date] [--older-than <days>]

# Delete branches
gitclean --prune-branches [main_branch] [--force] [--older-than <days>]

🚀 Installation

  1. Clone the repository
git clone https://github.com/nahtandev/gitclean.git
cd gitclean
  1. Make the tool executable
chmod +x bin/gitclean
  1. Install globally (optional)
sudo ln -s $(pwd)/bin/gitclean /usr/local/bin/gitclean

📖 Detailed Guide

📋 List Inactive Branches

# 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 Branches

# 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

⚠️ Note: The --force option allows deletion of non-merged branches.

🧩 Project Structure

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

👤 Author

Nathan Gnankadja

  • GitHub: @nahtandev
  • Specialized in web and backend development
  • Passionate about productivity tool development

📝 License

MIT License - see the LICENSE file for details.

⚠️ Warning

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

About

A Bash utility to easily clean up your inactive Git local branches.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages