If you've committed passwords, API keys or accidentally committed a large file you may need to remove it from your git history.
This can be done using the following simple filter-branch
command.
git filter-branch --tree-filter 'rm -f ./path/to/example' HEAD
Replace the path with the file you wish to remove.
Some instances where you should remove files from your git repository:
This command could be added to your .bashrc
file, in order to create a custom shortcut. For example:
Edit ~/.bashrc
, and add the following:
alias "git-rm-all-history"=git filter-branch --tree-filter 'rm -f $1' HEAD
Now, you can remove sensitive files by simply running git-rm-all-history path/to/file
.