Skip to content

Latest commit

 

History

History
161 lines (113 loc) · 4.11 KB

README.md

File metadata and controls

161 lines (113 loc) · 4.11 KB

git-cleaner

CI Release Go Version License GitHub Release

A cross-platform Go CLI tool that scans directories for .git directories, reports their sizes, and optionally optimizes repositories using git gc.

Features

  • Cross-platform: Works on macOS, Linux, and Windows WSL
  • Scan for repositories: Recursively finds all .git directories in a specified path
  • Size reporting: Shows disk usage for each repository's .git directory
  • Optimization: Runs git gc to optimize repositories and shows disk savings
  • Table output: Clean, formatted table showing repository paths and sizes

Installation

From Source

git clone <repository>
cd git-cleaner
make build

The binary will be in build/git-cleaner.

Cross-compilation

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

Quick Start

  1. Scan for repositories (dry-run):
./build/git-cleaner --scan ~/src
  1. Optimize repositories:
./build/git-cleaner --scan ~/src --clean

Command-Line Arguments

Flag Description
--scan PATH Directory to scan for .git directories (required)
--clean Run git gc in each repository and show disk savings

Examples

Scan a specific directory

./build/git-cleaner --scan ~/projects

Scan and optimize repositories

./build/git-cleaner --scan ~/projects --clean

This will:

  1. Scan for all .git directories
  2. Display their sizes in a table
  3. Run git gc in each repository's parent directory
  4. Rescan and show the disk savings achieved

Output Example

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

How It Works

  1. Scanning: Recursively walks through the specified directory tree, looking for directories named .git
  2. Size calculation: For each .git directory found, calculates the total size by walking through all files
  3. Optimization (with --clean): Runs git gc in each repository's parent directory to optimize the repository
  4. Rescan: After optimization, rescans to calculate the disk space saved

Platform Support

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().

Requirements

  • Go 1.21 or later
  • Git must be installed and available in PATH (for --clean functionality)

Development

Build

make build

Test

make test

Format, Lint, Vet

make fmt
make lint
make vet

Or run all checks:

make all

License

See LICENSE in the parent directory.