Skip to main content

git-history-cleaner

Version 1.0.0 CI Python 3.10+ License: MIT

Remove obsolete file versions from Git history while preserving the current branch's complete file tree. Version 1.0.0 generalizes the original cybergarage-pub-cleaner scripts into an installable Python CLI.

The tool snapshots the repository, produces a reviewable plan, rewrites an isolated clone using git-filter-repo, and verifies the result before an explicit push. It never rewrites your source working copy.

Requirements and installation

  • Python 3.10 or later and Git 2.36 or later on PATH.
  • macOS or Linux. Native Windows is not supported in 1.0.0.
  • Enough free disk space for a full mirror backup and a working clone.

Install from PyPI with:

pipx install git-history-cleaner==1.0.0
git-history-cleaner --version

To install from a source checkout:

python3 -m venv .venv
. .venv/bin/activate
python -m pip install .

git-filter-repo is installed as a Python dependency. The CLI can also be invoked as git history-cleaner when its executable is on PATH.

Quick start

From a local repository, analyze old PDFs and images under assets:

git-history-cleaner analyze --repo . --path assets \
  --ext pdf,png,jpg --work-dir ../cleanup-run

Read ../cleanup-run/plan.json. Then rewrite and verify the isolated snapshot:

git-history-cleaner rewrite --plan ../cleanup-run/plan.json
git-history-cleaner verify --run ../cleanup-run

The rewritten working copy is ../cleanup-run/rewritten. Your original repository and the mirror at ../cleanup-run/backup.git retain their old history. Neither analyze nor rewrite pushes anything.

After reviewing the result and coordinating with collaborators, explicitly choose the destination:

git-history-cleaner push --run ../cleanup-run \
  --remote git@github.com:example/project.git

The destination branch must still match the analyzed commit. Push uses an explicit --force-with-lease and asks for confirmation; --yes enables batch operation. Only the analyzed branch is pushed. Protected branches may reject it.

Selection examples

Paths are literal, repository-relative file or directory names, not globs. Repeated paths are combined. Filters for path, extension and size are intersected; exclusions take precedence. Deleted directories can be selected.

# Entire repository, old blobs of at least 10 MiB
git-history-cleaner analyze --repo . --path . --min-bytes 10485760

# Multiple paths with an excluded subtree
git-history-cleaner analyze --repo . --path assets --path archived \
  --exclude assets/vendor --ext pdf

# The original document/image extensions, explicitly selected
git-history-cleaner analyze --repo . --preset documents

# Remote source, explicit branch
git-history-cleaner analyze --repo https://github.com/example/project.git \
  --branch release --path assets --ext zip --json

With no path, extensions and size thresholds apply to the whole repository. An entirely unfiltered analysis requires explicit --path .. The default branch is the source's HEAD branch, not a hardcoded main. Local sources include committed history only; uncommitted files and stash are not part of the branch being rewritten.

What is preserved

  • Every blob used anywhere in the selected branch's current tree, regardless of filename extension or selected directory, is protected from blob stripping.
  • Blobs used by any unselected historical path are protected from global stripping. This conservative policy may retain some old selected versions.
  • Selected historical paths absent from the current tree are removed when all their recorded blob versions meet the size threshold. Their content can remain at other paths.
  • Verification requires the complete HEAD tree ID to remain identical, checks selected removals throughout branch history, and runs git fsck --full.
  • Other remote branches and tags are not changed. They may retain old objects.

Historical commits can lose files; empty commits and merge topology are retained. Commit IDs and signatures can change. This is history rewriting, not ordinary git gc. It is not a complete secret-erasure tool.

selected_blob_bytes is a sum of uncompressed blob sizes selected for global stripping, not an estimate of pack-file or server storage savings. It excludes additional effects of removing historical paths.

Existing clones and backups

A fresh clone is the simplest way to adopt the rewritten branch. To replay local commits made after the old branch tip:

git-history-cleaner rebase --repo /path/to/existing-clone --run ../cleanup-run

This requires a pushed run, a clean working tree, and the rewritten remote tip. It retains a backup branch and attempts to preserve merge structure. Resolve conflicts manually, or use git rebase --abort.

Delete a run only after verification and collaborator migration:

git-history-cleaner cleanup --run ../cleanup-run --include-backup

This deletes the entire run including the mirror backup. It validates the run manifest and refuses unexpected top-level files or symlinks. It does not scan directories by a filename prefix. A backup can retain substantial disk space until you deliberately remove it.

Documentation

Development

python3 -m venv .venv
. .venv/bin/activate
python -m pip install -e '.[dev]'
python -m unittest discover -s tests -v
python -m build
python -m twine check --strict dist/*

Tests create temporary local repositories and bare remotes; they never push to a hosted service. The GitHub workflows test macOS/Linux and build the distribution. Publishing is a separate, manually dispatched workflow using PyPI Trusted Publishing; see the release guide for the required account configuration.

MIT licensed. See LICENSE.

Metadata

Release files for git-history-cleaner 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for git-history-cleaner 1.0.0
File Size Uploaded Provenance Actions
git_history_cleaner-1.0.0.tar.gz 24.3 kB With provenance Details for git_history_cleaner-1.0.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for git-history-cleaner 1.0.0
File Interpreter ABI Platform Actions
git_history_cleaner-1.0.0-py3-none-any.whl Python 3 none any Details for git_history_cleaner-1.0.0-py3-none-any.whl

Total release size: 37.1 kB

Release files / git_history_cleaner-1.0.0.tar.gz

Download URL git_history_cleaner-1.0.0.tar.gz
Size 24.3 kB
Tags Source
SHA-256 checksum
How to use checksums
7959fad1da63084ec0702fd1cbdc908aa4896228dd3830bfee7954cd5eae160b
BLAKE2b-256 checksum
How to use checksums
6773a0fc01bbfabfbc6b9f61b965e738c85628cd254501e4c5709ad2d6b4aa7f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 27, 2026.

Transparency log

Release files / git_history_cleaner-1.0.0-py3-none-any.whl

Download URL git_history_cleaner-1.0.0-py3-none-any.whl
Size 12.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
187db92169d5194d62f28496df420e779b0a6ee8e5a676ccbec499b7582c990d
BLAKE2b-256 checksum
How to use checksums
ef6f604b5f46f83b1cd21902597dfc52aaa62178e7afe5e58a5d145de405a82c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 27, 2026.

Transparency log

Security for git-history-cleaner 1.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for git_history_cleaner-1.0.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 27, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page