When you are putting an existing project into a GIT repository, or starting fresh, you will want to retain your folder structure, including all cache folders etc, but may want ignore the files held with in them. This isn’t obvious as by adding the lines like this to your global .gitignore file will ignore all files and the folder as well:
Instead, try putting a .gitignore file within the folder, with the following content:
# Ignore everything in this directory * # Except this file !.gitignore
This tip was found on Stack Overflow.