Skip to content

Instantly share code, notes, and snippets.

@mjuenema
Last active July 2, 2017 22:48
Show Gist options
  • Save mjuenema/f1921f6fb9e9fdff7143f18c6bc51197 to your computer and use it in GitHub Desktop.
Save mjuenema/f1921f6fb9e9fdff7143f18c6bc51197 to your computer and use it in GitHub Desktop.
BFG Git Repo Cleaner

BFG Git repo cleaner

The BFG Git repo cleaner is a simpler, faster alternative to git-filter-branch for cleansing bad data out of your Git repository history, e.g.

  • Removing Crazy Big Files
  • Removing Passwords, Credentials & other Private data

Create a backup of your current working copy of the repository.

$ mv my-repo.git my-repo.git.bak

Mirror clone the repository.

$ cd /tmp
$ git clone --mirror [email protected]:mjuenema/my-repo.git

Make a backup in case something goes wrong.

$ tar cvfz my-repo.tgz my-repo.git

Check the online help.

$ ~/.local/bin/bfg --help

Example: Remove files

$ bfg --delete-files id_{dsa,rsa}  my-repo.git

Example: Remove large files

$ bfg --strip-blobs-bigger-than 50M  my-repo.git

Example: Remove text from files.

This didn't work for me but maybe I made a mistake.

$ vim /tmp/to_remove
glob: mysecretpassword
regex: my.+secret

$ bfg --replace-text /tmp/replace.txt python-sigfox-backend-api.git

Finally clean up the mirror repo and push it.

$ cd my-repo.git
$ git reflog expire --expire=now --all && git gc --prune=now --aggressive
$ git push

Then create a new working clone.

$ git clone [email protected]:mjuenema/python-sigfox-backend-api.git

Check the BFG web site for other examples.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment