CLI tool to detect large files in Git history and working directory with pre-commit hook support.
Project description
Gitrim
Keep your git repositories clean and lean!
Gitrim is a powerful, user-friendly CLI tool to help you detect, block, and remove large files from your git repositories and working directories. It also helps you prevent accidental commits of oversized files with a pre-commit hook.
🚀 Features
- 🔍 Scan git history for large files
- 📂 Scan working directory for large files
- 🗑️ Remove large files from the working directory (with dry-run and confirmation)
- 🛡️ Generate a pre-commit hook to block large files from being committed
- 📏 Flexible size threshold (KB, MB, GB)
- 📊 Summary statistics after each operation
- 🤝 User-friendly CLI with helpful usage info
- ⚠️ Clear error handling and confirmation prompts
🛠️ Installation
-
Clone this repository:
git clone https://github.com/yadavkapil23/Gitrim.git cd Gitrim
-
(Recommended) Create and activate a virtual environment:
python -m venv gitrim-env # On Windows: gitrim-env\Scripts\activate # On macOS/Linux: source gitrim-env/bin/activate
-
Install dependencies:
pip install -r requirements.txt
-
(Optional) Install in editable/development mode:
pip install -e .
-
Verify installation:
gitrim --help
⚡ Usage
Run gitrim to see all commands and examples:
$ gitrim
1. 🔍 Scan git history for large files
$ gitrim large-files --threshold 5 --unit MB
- Scans the entire git history for files larger than 5 MB.
2. 📂 Scan working directory for large files
$ gitrim scan-working-dir --threshold 500 --unit KB
- Scans only the current working directory (not git history) for files larger than 500 KB.
3. 🗑️ Remove large files from working directory
- Dry run (no deletion):
$ gitrim remove-large-files --threshold 2 --unit MB --dry-run
- Actually delete (with confirmation):
$ gitrim remove-large-files --threshold 2 --unit MB
- Actually delete (no confirmation):
$ gitrim remove-large-files --threshold 2 --unit MB --yes
4. 🛡️ Generate a pre-commit hook
$ gitrim generate-pre-commit-hook --threshold 1 --unit MB
- Creates a
.git/hooks/pre-commitscript that blocks commits containing files above the threshold.
5. Get help for any command
$ gitrim --help
# or
$ gitrim <command> --help
📦 Components
-
gitrim/cli.py
- The main CLI entry point. Defines all commands and options using Click.
- Handles user input, help messages, and command dispatch.
-
gitrim/cleaner.py
- Contains all core logic for scanning, reporting, removing large files, and generating pre-commit hooks.
- Handles both git history and working directory operations.
- Provides summary statistics and user feedback.
-
requirements.txt
- Lists all Python dependencies:
click,rich,GitPython.
- Lists all Python dependencies:
-
README.md
- This file! Explains installation, usage, and features.
-
pyproject.toml
- Used for editable installs and packaging.
📝 Example Workflow
- Scan your repo for large files:
$ gitrim large-files --threshold 10 --unit MB
- Scan your working directory:
$ gitrim scan-working-dir --threshold 500 --unit KB
- Remove large files (with confirmation):
$ gitrim remove-large-files --threshold 5 --unit MB
- Block large files from being committed:
$ gitrim generate-pre-commit-hook --threshold 2 --unit MB
📄 License
MIT License. See LICENSE for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file gitrim-0.1.0.tar.gz.
File metadata
- Download URL: gitrim-0.1.0.tar.gz
- Upload date:
- Size: 5.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f40301a85019affb453b05a8e1181b2161acef5245eff28d5a18e28681cd1de5
|
|
| MD5 |
46f847e84628d4d9274d0bff88e044e1
|
|
| BLAKE2b-256 |
f0d61a6467c31f284239657ec6cc0cf29fd8cdaa459ca0959e7ea878caa48fce
|
File details
Details for the file gitrim-0.1.0-py3-none-any.whl.
File metadata
- Download URL: gitrim-0.1.0-py3-none-any.whl
- Upload date:
- Size: 5.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e861d6c90b46b995c294f1fd9aab0f52c0a6417ab41cb0e5426b74efb21d26ef
|
|
| MD5 |
1d39984db806265740eb4526491d88a3
|
|
| BLAKE2b-256 |
d15bafb1c9a14876e4cd9ebea8cf3ecf8d27904914ba477fab822d15993212d4
|