Keep git out of your cache folders

My good friend Adam Wiggall just shared a quick and easy way to keep git out of cache folders while still allowing the bare folder to be added to the repo.

First off, this is best done before any actual data is added to those folders and then committed to the repo. The technique is quite simple and involves only two steps.

First, add an empty .gitkeep file in the cache folder to be added to the repo. In this case it’s the ever-annoying ExpressionEngine cache folder:


Then, add the following lines to this repo’s gitignore:


This same technique can be used for .sass-cache, etc. Now you have an empty (initially) folder as required for the system to function, without all the contents polluting your repository.

What do you do if you need to implement this after the folder is already populated? Simple. Run the following command from your command prompt:

git rm _system/expressionengine/cache/ -r --cache


blog comments powered by Disqus