# Git filter-branch So today I noticed my git repository was taking too much disk space and discovered it was due to bundler caching gems. At first I thought I'd just remove `vendor/cache` directory it be done with it. But that's not how git works, is it? That's how I came across `git filter-branch`. The following command will remove the `vendor/cache` directory and all its references throughout your repository history. `git filter-branch --force --index-filter "git rm --cached --ignore-unmatch -r vendor/cache"` ## Undoing it And, should you realise you shouldn't have done that, git is also there for you. Whenever you use `filter-branch`, git creates a backup of the previous state for you at `.git/refs/original/refs/heads/NAME_OF_YOUR_BRANCH`. Meaning all you have to do is run: `git reset --hard refs/original/refs/heads/NAME_OF_YOUR_BRANCH` You're welcome ;)