How can I completely remove a file from a git repository?

The tool you want is git filter-branch. Its usage is described here, but basically:

$ git filter-branch --tree-filter 'rm -f my_file' HEAD

will remove “my_file” from every commit.

Notice that this rewrites every commit, so if you push into a remote repository, you have to (a) force the update, and (b) everyone else who pulled from you will now have duplicate commits (since you rewrote the history), as described on the git rebase man page.

Leave a Comment