I like to keep my blogs in git repos. For small blogs this works great, but for blogs with a ton of images this quickly becomes a problem. For example, my wife’s blog has 4GB of images. git isn’t really designed to handle that.
So I decided to take out the images. Specifically, I decided to exclude wp-content/uploads from her git repo. Just removing the images isn’t good enough, because they are saved in the history of the repo. For a quick and easy way to remove one or more files completely from git, use BFG.
These are the steps I took:
The last step is to clone a fresh copy of the repo. You’ve modified the history of the repo, so you shouldn’t use any existing clones. Be careful not to lose your images! They aren’t in git anymore!
It is important to note that in step #8 you cannot use a full folder path. It won’t let you even if you try. So if you have something else called uploads or with uploads in the path that you’ve previously deleted, it’ll be wiped out, too.
It is also important to note that step #8 won’t do anything if you skip step #2. BFG makes the assumption that you don’t want to get rid of anything that is in your latest commit.
This also works great for removing sensitive information from a repo, for example if you commit a password to a public repo. BFG even lets you search and replace text, so you can simply replace an accidentally committed password with something else instead of deleting the files.