Skip to content

Instantly share code, notes, and snippets.

@pdrok
Created May 17, 2022 14:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pdrok/7ef5c54dd62054e9adf12cf00a7ae8bd to your computer and use it in GitHub Desktop.
Save pdrok/7ef5c54dd62054e9adf12cf00a7ae8bd to your computer and use it in GitHub Desktop.
The BFG Repo-Cleaner is a tool that's built and maintained by the open source community. It provides a faster, simpler alternative to git filter-branch for removing unwanted data.

Download the latest version from the site: https://rtyley.github.io/bfg-repo-cleaner/

Create a folder:

mkdir clean-repo

Inside the this folder create a txt file with the password o sensitive data you want to revove

cd clean-repo
echo "mySuperPassword" > passsword.txt

clone a fresh copy of your repo, using the --mirror flag:

git clone --mirror git://example.com/some-repo.git

This is a bare repo, which means your normal files won't be visible, but it is a full copy of the Git database of your repository, and at this point you should make a backup of it to ensure you don't lose anything.

Now you can run the BFG to clean your repository up:

java -jar bfg-1.14.0.jar --replace-text passwords.txt some-repo.git

Access your repo folder to run the follow command:

cd some-repo.git
git reflog expire --expire=now --all 
git gc --prune=now --aggressive
git push

All you sensitive data on your commit history was replace with ***REMOVED***

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