bfg
Remove large files from Git history
TLDR
Remove a file with sensitive data but leave the latest commit untouched
Remove all text mentioned in the specified file wherever it can be found in the repository's history
SYNOPSIS
bfg [options] <repository>
or
java -jar bfg.jar [options] <repository>
PARAMETERS
--delete-files <name>
Delete files matching exact filename(s) (supports globs/wildcards)
--delete-folders <name>
Delete folders matching exact name(s) (globs supported)
--strip-blobs-bigger-than <size>
Delete blobs larger than size (e.g., 100M, 1G)
--replace-text <expressions.txt>
Replace text patterns from file (protects <password> etc.)
--no-blob-protection
Allow deletion of blobs still referenced in working tree
--mirror
Treat repo as mirror (fetch/push automatically)
--all-text
Scan all files as text (not just known types)
-bi <size>
Short for --strip-blobs-bigger-than <size> --no-blob-protection
--verbose
Enable verbose logging
--help
Show full usage
DESCRIPTION
The BFG Repo-Cleaner is a simpler, faster alternative to git-filter-branch for cleaning Git repository history. It removes large files, obfuscates credentials, or deletes unwanted data across all commits without modifying commits unnecessarily. Designed for speed, it processes repositories much quicker than native Git tools by leveraging Scala and Java, ignoring small files and focusing on blobs. Use it to shrink bloated repos caused by accidentally committed large binaries or sensitive info.
BFG rewrites Git history by replacing unwanted blobs with references to smaller ones or deletions. Post-cleaning, run git reflog expire and git gc to reclaim space. Ideal for monorepos or after CI failures uploading artifacts. It's self-contained as a JAR file: download and run with java -jar bfg.jar. Supports mirroring for remote repos and protects blobs by default to avoid breaking working trees.
CAVEATS
Always backup repo first: BFG rewrites history irreversibly. Requires force-push (git push --force) to share changes. Cannot fix refs outside main refs/heads or refs/tags. Java 8+ required. Incompatible with shallow clones.
INSTALLATION
Download JAR from GitHub releases or install via brew (brew install bfg), apt (snap install bfg). Run directly or symlink as bfg.
EXAMPLE USAGE
bfg --delete-files secrets.txt myrepo.git
bfg --strip-blobs-bigger-than 50M --mirror myrepo.git
Follow with git reflog expire --expire=now --all && git gc --prune=now --aggressive.
HISTORY
Developed by R. Tyler Croy in 2013 as Scala-based tool on GitHub (rtyley/bfg-repo-cleaner). Inspired by git-filter-branch limitations; actively maintained with 10k+ stars. Widely used in open-source for repo hygiene.
SEE ALSO
git-filter-branch(1), git(1), git-gc(1)


