Showing posts with label secret. Show all posts
Showing posts with label secret. Show all posts

2021-09-02

Remove Secrets from git Repository

Sometimes you accidentally create a commit and push a sensitive data to the git server, here's how you can remove the secrets from the git repo using https://rtyley.github.io/bfg-repo-cleaner/
  1. clone a repo you want to clean, change directory to newly cloned folder
  2. create a file containing all the lines/secrets you want to remove 
  3. run  java -jar ~/Downloads/bfg-1.14.0.jar --replace-text /tmp/.env .
  4. run git reflog expire --expire=now --all && git gc --prune=now --aggressive 
  5. foreach branch that contains the changes, do git checkout branchName && git push --force
After force push, the offending lines will be replaced with "***REMOVED***" line.