Skip to content

Instantly share code, notes, and snippets.

@palexander
Created November 18, 2011 01:35
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save palexander/1375271 to your computer and use it in GitHub Desktop.
Save palexander/1375271 to your computer and use it in GitHub Desktop.
Remove a password from Git's history
# Sync with the remote master
git pull
# Force your clone to look like HEAD
git reset --hard
# AGAIN, A WARNING: This can really break stuff!
# Run your filter branch command, replacing all instances of "password" with "your_password"
# The example looks for Ruby files ("*.rb"), you can change this to match your needs
git filter-branch --tree-filter 'git ls-files -z "*.rb" |xargs -0 perl -p -i -e "s#(password)#your_password#g"' -- --all
# Overwrite your master with local changes
git push origin master --force
@plantpurecode
Copy link

This is a godsend. Thank you so much for putting this up! :)

@JosephGaiser
Copy link

Still useful all these years later 👍

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