Filed under Coding
Keep git out of your cache folders
Keep the required folder in the repository while leaving all of its noisy generated files out of git.
My good friend 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 is the ever annoying ExpressionEngine cache folder:
_system/expressionengine/cache/.gitkeep
Then, add the following lines to this repo's gitignore:
_system/expressionengine/cache/*
!_system/expressionengine/cache/.gitkeep
This same technique can be used for the Sass cache and other generated folders. Now you have an empty folder, initially, 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. Remove the cached files from the index with git rm using the recursive option, then commit the change. The files stay on disk, but git stops tracking them.