A cross-platform Go CLI tool that scans directories for .git directories, reports their sizes, and optionally optimizes repositories using git gc.
- Cross-platform: Works on macOS, Linux, and Windows WSL
- Scan for repositories: Recursively finds all
.gitdirectories in a specified path - Size reporting: Shows disk usage for each repository's
.gitdirectory - Optimization: Runs
git gcto optimize repositories and shows disk savings - Table output: Clean, formatted table showing repository paths and sizes
git clone <repository>
cd git-cleaner
make buildThe binary will be in build/git-cleaner.
Build for multiple platforms:
make build-all # Builds for Linux (amd64/arm64) and macOS (amd64/arm64)Or build individually:
make build-linux # Linux builds only
make build-darwin # macOS builds only- Scan for repositories (dry-run):
./build/git-cleaner --scan ~/src- Optimize repositories:
./build/git-cleaner --scan ~/src --clean| Flag | Description |
|---|---|
--scan PATH |
Directory to scan for .git directories (required) |
--clean |
Run git gc in each repository and show disk savings |
./build/git-cleaner --scan ~/projects./build/git-cleaner --scan ~/projects --cleanThis will:
- Scan for all
.gitdirectories - Display their sizes in a table
- Run
git gcin each repository's parent directory - Rescan and show the disk savings achieved
Scanning /Users/me/src for .git directories...
Found 5 repositories:
+----------------------------+----------+-------+
| Repository Path | .git Size| Items |
+----------------------------+----------+-------+
| /Users/me/src/project1 | 45.23 MB | 1234 |
| /Users/me/src/project2 | 12.34 MB | 567 |
| /Users/me/src/project3 | 8.90 MB | 234 |
+----------------------------+----------+-------+
| TOTAL | 66.47 MB | 2035 |
+----------------------------+----------+-------+
After running with --clean:
Disk savings: 12.34 MB (18.57%)
Cleaned 5 repositories
- Scanning: Recursively walks through the specified directory tree, looking for directories named
.git - Size calculation: For each
.gitdirectory found, calculates the total size by walking through all files - Optimization (with
--clean): Runsgit gcin each repository's parent directory to optimize the repository - Rescan: After optimization, rescans to calculate the disk space saved
This tool works on:
- macOS: Native support (amd64 and arm64)
- Linux: Full support (amd64 and arm64)
- Windows WSL: Full support through Linux compatibility
All paths use filepath.Join() for cross-platform compatibility. Home directory expansion (~) works on all platforms via os.UserHomeDir().
- Go 1.21 or later
- Git must be installed and available in PATH (for
--cleanfunctionality)
make buildmake testmake fmt
make lint
make vetOr run all checks:
make allSee LICENSE in the parent directory.