Skip to content

Instantly share code, notes, and snippets.

@froi
Last active December 30, 2015 10:59
Show Gist options
  • Save froi/7819623 to your computer and use it in GitHub Desktop.
Save froi/7819623 to your computer and use it in GitHub Desktop.
Purge file from git history. Useful if like me you commit/push sensitive data, aka credentials. Command was copied from the excellent Github article: https://help.github.com/articles/remove-sensitive-data

1. Change into repo folder

cd my-repo

2. Change into branch you want to modify if not already in it

git checkout <branch>

3. Purge the file

This is the nuclear option. Have to be sure this is what is wanted! Substitute with the name of the file you want gone!

git filter-branch --force --index-filter \
 'git rm --cached --ignore-unmatch <filename>' \
 --prune-empty --tag-name-filter cat -- --all

4. Push back into remote

git push origin <branch>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment