Skip to content

A fast Rust CLI to scan and clean files and directories ignored by .gitignore across your project. It detects ignored items, shows sizes, and lets you interactively delete them.

License

Notifications You must be signed in to change notification settings

jordyfontoura/gitclean

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

4 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

🧹 gitclean

Clean your Git projects like a pro

A blazingly fast Rust CLI that scans and removes files ignored by .gitignore β€” interactively and safely.

Crates.io License: MIT Rust

Installation β€’ Features β€’ Usage β€’ Examples β€’ Library


🎯 Why gitclean?

Ever wondered how much disk space those node_modules, target, or .next folders are eating up across your projects? gitclean gives you instant visibility and safe cleanup of all ignored files and directories.

✨ What makes it special?

  • ⚑ Blazingly Fast – Written in Rust with parallel processing
  • 🎯 Smart Detection – Recursively respects all nested .gitignore files
  • πŸ”’ Safe by Default – Preserves secrets like .env files automatically
  • πŸ“Š Visual Insights – See sizes before you delete
  • 🎨 Beautiful TUI – Interactive multiselect with sorted results
  • πŸ›‘οΈ Zero Risk – Review and confirm before any deletion

πŸš€ Installation

Install directly from crates.io:

cargo install gitclean

That's it! Now you can use gitclean anywhere.


✨ Features

Feature Description
πŸ”„ Recursive Scanning Collects rules from all .gitignore files in your project tree
🎯 Custom Patterns Add extra ignore patterns via CLI (-i ".env*,.config*")
πŸ” Smart Preservation Automatically protects common secret/config files
⚑ Parallel Processing Lightning-fast size computation with WalkDir + Rayon
🎨 Interactive TUI Beautiful multiselect interface with sizes, sorted descending
πŸ“Š Detailed Logging Informative spinners and progress indicators

πŸ“– Usage

gitclean <PATH> [OPTIONS]

Options

<PATH>                    Project root directory to scan
-i, --ignores <PATTERNS>  Extra ignore patterns (comma-separated)
-h, --help                Print help information
-V, --version             Print version information

πŸ’‘ Examples

Clean current directory

gitclean .

Output:

🧹 gitclean v1.0.0
πŸ“‚ Root: /home/user/projects/my-app
πŸ“‹ Default patterns: 15
🎯 Extra patterns: 0

β ‹ Loading .gitignore files...
βœ“ Found 3 .gitignore files

β ‹ Scanning ignored items...
βœ“ Found 127 ignored items (45 dirs, 82 files)

β ‹ Computing sizes...
βœ“ Sizes computed

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  Select items to delete (Space to toggle) β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

  [ ] node_modules/          1.2 GB
  [ ] target/                856 MB
  [ ] .next/                 234 MB
  [ ] dist/                  89 MB
  [ ] coverage/              12 MB

Scan specific project

gitclean ~/projects/my-app

Add custom ignore patterns

gitclean . -i ".env*,.config*,*.log"

This will additionally ignore:

  • All files starting with .env
  • All files starting with .config
  • All .log files

🎨 Interactive Experience

gitclean provides a delightful CLI experience:

  1. πŸ”„ Spinner animations while scanning
  2. πŸ“Š Progress indicators for long operations
  3. πŸ“‹ Organized results sorted by size (largest first)
  4. βœ… Multi-select interface to choose what to delete
  5. βœ“ Confirmation logs showing freed space

πŸ“š Library Usage

Use gitclean as a library in your own Rust projects:

use gitclean::{
    gather_gitignores,
    scan_ignored_files,
    calculate_sizes,
    format_size
};
use indicatif::ProgressBar;
use std::path::Path;

fn main() -> anyhow::Result<()> {
    let root = Path::new(".").canonicalize()?;
    let spinner = ProgressBar::hidden();
    let extra: Vec<String> = vec![];
    
    // Gather all .gitignore rules
    let map = gather_gitignores(&root, &spinner, &extra)?;
    
    // Scan for ignored files
    let ignored = scan_ignored_files(&root, &map, &spinner)?;
    
    // Calculate sizes
    let items = calculate_sizes(ignored, &spinner, &root)?;
    
    println!("Found {} ignored items", items.len());
    for item in items {
        println!("{}: {}", item.path.display(), format_size(item.size));
    }
    
    Ok(())
}

πŸ—οΈ Architecture

gitclean is built with a clean modular structure:

src/
β”œβ”€β”€ lib.rs         β†’ Public API exports
β”œβ”€β”€ patterns.rs    β†’ Default ignore patterns
β”œβ”€β”€ types.rs       β†’ Core types (ItemWithSize)
β”œβ”€β”€ ignore.rs      β†’ .gitignore parsing
β”œβ”€β”€ scan.rs        β†’ Scanning logic
β”œβ”€β”€ size.rs        β†’ Size computation
β”œβ”€β”€ fsops.rs       β†’ File operations
β”œβ”€β”€ util.rs        β†’ Utilities (format_size)
└── main.rs        β†’ CLI interface

Each module is designed to be reusable and testable.


πŸ› οΈ Development

Run tests

cargo test

Build release

cargo build --release
./target/release/gitclean .

Run locally

cargo run -- .

🀝 Contributing

Contributions are welcome! Here's how you can help:

  1. 🍴 Fork the repository
  2. 🌿 Create a feature branch (git checkout -b feature/amazing-feature)
  3. πŸ’Ύ Commit your changes (git commit -m 'Add amazing feature')
  4. πŸ“€ Push to the branch (git push origin feature/amazing-feature)
  5. πŸŽ‰ Open a Pull Request

Please read CONTRIBUTING.md and follow the CODE_OF_CONDUCT.md.


πŸ“ License

MIT Β© 2025 Jordy Fontoura


Made with ❀️ and πŸ¦€ Rust

⬆ Back to top

About

A fast Rust CLI to scan and clean files and directories ignored by .gitignore across your project. It detects ignored items, shows sizes, and lets you interactively delete them.

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Packages

No packages published

Languages