Published on

Git tip: Ignoring files with a trash folder

While Git allows you to keep track of every single change to a file within a repository, it is sometimes useful to have an area in your project where you can drop unversioned files, if only to leave notes, download dumps, store curl results, etc.

Rather than modifying the project's .gitignore file or messing with Git's cache to avoid versioning these files, there is a simple trick that does exactly this:

  1. Create a trash folder anywhere in the project (the name doesn't matter, this is my personal convention)
  2. Create a .gitignore file at its root with * as content
  3. Add any file to this folder, it will not be versioned.

Git supports adding multiple .gitignore files to a single repository, so here we simply declare one in a new subfolder with a wildcard that tells it that none of its files should be versioned.

I can't remember where I discovered this handy trick several years ago, but since I discovered it none of my projects have escaped it!