Git-Cleaner: Automating Branch Management
A Rust-based CLI tool to automatically clean up merged git branches, improving local development hygiene and reducing clutter.
Problem Statement
In fast-paced development environments, local git repositories often accumulate hundreds of stale branches. Manually checking `git branch --merged` and deleting them one by one is tedious and error-prone. Developers often fear deleting the wrong branch or losing work.
Solution
**Git-Cleaner** is a high-performance CLI tool built in **Rust** that safely identifies and removes local branches that have already been merged into the main line development (e.g., `main`, `master`, `dev`).
//Key Features
Technical Implementation
The core logic relies on `git2-rs`, providing direct bindings to `libgit2` for maximum speed and reliability.
```rust
fn get_merged_branches(repo: &Repository, main_branch: &str) -> Result<Vec<String>, Error> {
let main = repo.find_branch(main_branch, BranchType::Local)?;
let main_tree = main.get().peel_to_tree()?;
// ... logic to walk graph
}
```
The CLI interface is built using `clap` for argument parsing and `dialoguer` for the interactive selection menu.
Impact
Git-Cleaner has reduced branch clutter by **90%** for early adopters and is now part of the standard onboarding toolkit for my team.