BFG Repo-Cleaner
30 May 2017 - DaveBFG Repo-Cleaner is a good tool to clean up a Git repository before sharing.
Removes large or troublesome blobs like git-filter-branch does, but faster. And written in Scala.
$ bfg --strip-blobs-bigger-than 100M --replace-text banned.txt repo.git
Replace all passwords and listed in a file (prefix lines ‘regex:’ or ‘glob:’ if required) with
***REMOVED***
wherever they occur in your repository :
$ bfg <strong>--replace-text passwords.txt</strong> my-repo.git
Delete all files named ‘id_rsa’ or ‘id_dsa’ :
$ bfg <strong>--delete-files id_{dsa,rsa}</strong> my-repo.git
Using BFG on Windows:
- Use Git Bash or Windows 10 Bash.
- Download and install Java from here.
- Download BFG here.
- Make an alias for BFG:
java -jar bfg.jar $*
- Make a replace.txt file:
PASSWORD # Replaces PASSWORD with ***REMOVED***
PASSWORD==>TEST # Replaces PASSWORD with TEST
PASSWORD==> # Replaces PASSWORD with blank
# You can use Regular Expressions also
- Run this command in the repo folder from Git Bash or Win10 Bash:
bfg –replace-text replace.txt
- When bfg is done run these commands
git reflog expire –expire=now –all && git gc –prune=now — aggressive
git push # -f may be needed
Notes:
- I had already pushed the repo and shared it. That got complicated by multiple branches. My fault. It would have been much simpler to run bfg before sharing.
- I fumbled a bit trying to get bfg running in Windows command shell.
Resources:
- StackOverflow
-
Removing Keys, Passwords and Other Sensitive Data from Old Github Commits on OSX
- BFG Repo-Cleaner – Removes large or troublesome blobs like git-filter-branch does, but faster. And written in Scala.
- Using BFG Repo Cleaner tool to remove sensitive files from your git repo
- The BFG Repo Cleaner