Docker image for BFG Repo-Cleaner, a tool for removing large files and sensitive data from Git repos
7.2K
A Docker image for the BFG Repo-Cleaner, a simpler, faster alternative to
git filter-branchfor removing large files, passwords, credentials, and other unwanted data from Git repository history.
Current BFG Version: 1.15.0
Run BFG by mounting your repository directory:
docker run --rm -v /path/to/repo:/work jonlabelle/bfg [options]
Show BFG help:
docker run --rm jonlabelle/bfg --help
Warning
**BFG rewrites Git history, which can be destructive. Follow these steps first:**
Important
BFG protects your current commit by default. Files in your HEAD commit are never modified—only their history is cleaned. [Learn more](https://rtyley.github.io/bfg-repo-cleaner/#protected-commits)
Example workflow for removing large files from a repository and syncing across the team:
# Clone the repository as a bare mirror (safer for rewriting history)
git clone --mirror https://github.com/user/repo.git
# Run BFG to remove large files
docker run --rm -v $(pwd):/work jonlabelle/bfg --strip-blobs-bigger-than 100M repo.git
# Enter the repository directory (bare repo's have .git suffix)
cd repo.git
# Clean up and garbage collect
git reflog expire --expire=now --all
git gc --prune=now --aggressive
# Force push changes back to the remote repository
git push --force-with-lease
After pushing, other team members with local clones need to update their repositories:
# Fetch the rewritten history and reset to match the remote
git fetch origin
git reset --hard origin/main
Warning
`git reset --hard` will discard any uncommitted changes. Commit or stash work before running this command.
Remove all files named passwords.txt from history:
docker run --rm -v $(pwd):/work jonlabelle/bfg --delete-files passwords.txt my-repo.git
Remove a folder from all commits:
docker run --rm -v $(pwd):/work jonlabelle/bfg --delete-folders .secrets my-repo.git
Create a replacements.txt file with your replacements, then run:
docker run --rm -v $(pwd):/work jonlabelle/bfg --replace-text replacements.txt my-repo.git
Example replacements.txt format:
PASSWORD1==>***REMOVED***
api_key_12345==>***REMOVED***
Remove all .log, .zip, or .db files from history:
docker run --rm -v $(pwd):/work jonlabelle/bfg --delete-files '*.{log,zip,db}' my-repo.git
Remove accidentally committed SSH keys and certificates:
docker run --rm -v $(pwd):/work jonlabelle/bfg --delete-files '*.{pem,key,p12,pfx}' my-repo.git
Or remove specific key files:
docker run --rm -v $(pwd):/work jonlabelle/bfg --delete-files '{id_rsa,id_rsa.pub,private.key}' my-repo.git
Remove .env files containing secrets:
docker run --rm -v $(pwd):/work jonlabelle/bfg --delete-files '{.env,.env.local,.env.production}' my-repo.git
Remove specific blob IDs listed in a file:
docker run --rm -v $(pwd):/work jonlabelle/bfg --strip-blobs-with-ids blob-ids.txt my-repo.git
Protect the last 5 commits from being modified (only clean older history):
docker run --rm -v $(pwd):/work jonlabelle/bfg --delete-files credentials.json --protect-blobs-from HEAD~5 my-repo.git
Remove large files AND delete sensitive files:
docker run --rm -v $(pwd):/work jonlabelle/bfg \
--strip-blobs-bigger-than 50M \
--delete-files '{*.key,*.pem,secrets.json}' \
my-repo.git
For more options and detailed documentation, see the BFG Repo-Cleaner website.
BFG protects your HEAD commit by default. If files you want to remove are in your latest commit:
--no-blob-protection flag (not recommended)If git push --force-with-lease is rejected:
--force instead (less safe but works if you're certain)After BFG, you must run cleanup commands and force push:
cd my-repo.git
git reflog expire --expire=now --all
git gc --prune=now --aggressive
git push --force-with-lease
Other clones won't see size reduction until they re-clone or reset.
On Windows, use forward slashes and ensure path sharing is enabled in Docker Desktop:
docker run --rm -v "${PWD}:/work" jonlabelle/bfg [options]
Create a shell function to use BFG like a native command without typing the full Docker command each time.
Add to ~/.bashrc or ~/.zshrc:
bfg() {
docker run --rm -v "$(pwd):/work" jonlabelle/bfg "$@"
}
Add to your PowerShell profile:
function bfg {
docker run --rm -v "${PWD}:/work" jonlabelle/bfg $args
}
Content type
Image
Digest
sha256:476d9ce1b…
Size
133.2 MB
Last updated
about 4 hours ago
docker pull jonlabelle/bfg