removing passwords from git repositories

04 Oct 2018

Here’s how to remove a password from any file, in all revisions, in a git repository:

$ git filter-branch --tree-filter \
    "find . -type f -exec sed -i -e 's/password/XXX/g' {} \;"

Another handy one, deleting all the lines containing word:

$ git filter-branch --tree-filter \
    "find . -type f -exec sed -i -e '/word/d' {} \;"

Now, to force push your changes to a remote repository:

$ git push -f

That’s it, happy safe coding, 😊