Have you messed GIT with any big and unwanted content? Committing binaries, huge media files or new test project? Last refactoring found a lot of duplicate code? It is a quite common problem and your repository grows all the time. It is recommended, e.g. to remove all binary files from repository. You can also remove them from repository history to optimize its size. The most common case is removing directory from GIT history.
Detailed usage of git filter-branch is described at Permanently remove files and folders from Git repo. This tutorial has just the most basic steps.
Identify commit in history
You can edit while repository history, but it can mess up other things accidentally. It is suggested to repair just part of history with unwanted directory.
How to show commit history:
One log record can look like this:
Author: root <email@example.com>
Date: Wed Mar 30 09:42:38 2016 +0200
stm – repair filter + sort
Identify commit and save first 8 characters from its hash-code.
Filter history/remove directory
You can filter history from identified commit to last/HEAD.
git filter-branch --tree-filter 'rm -rf home/big' 1ba9226c..HEAD
For removing directory from whole history use
git filter-branch --tree-filter 'rm -rf home/big' HEAD
Commit and push GIT history changes
Last step is to push all changes and master records.
git push origin master --force
Whole process is finished. You can also force local garbage collector, but GIT will execute it in defined period by itself.