Skip to content

Instantly share code, notes, and snippets.

@martinratinaud
Created August 9, 2021 04:03
Show Gist options
  • Save martinratinaud/b01c615c131693a9097755a85a0cbf3e to your computer and use it in GitHub Desktop.
Save martinratinaud/b01c615c131693a9097755a85a0cbf3e to your computer and use it in GitHub Desktop.
Remove a password (or unwanted string) commited in github (or gitlab) from git history
#!/bin/bash
git filter-branch --tree-filter "find . -name 'ops/roles/ota/files/.env' -exec sed -i -e \
's/<thepasswordtoremove>/***REMOVED***/g' {} \;"
git reflog expire --expire=now --all && git gc --prune=now --aggressive
git push --force --all
# If this commit was hosted on github, you will still be able to access the failing commit on the web
# which is not what you want
# This is because GitHub needs to run garbage collection and this will be done manually upon request
# This way dangling commit will be removed
open https://support.github.com/contact?tags=rr-general-technical
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment