Will Murphy's personal home page

Ignore a Scratchwork Folder

I wanted to share a small trick that has helped me be a little more productive this year.

Here’s the TL;DR:

$ echo 'DevScratch/' >> ~/.gitignore
$ git config --global core.excludesFile ~/.gitignore
# (put some notes and scratchwork in the DevScratch folder of whatever repo I'm in)

(Actually I use willtmp, but your name’s probably not Will.)

This trick solves a problem that I’ve had with file organization since forever: where do I keep my scratchwork? (By “scratwork,” I just mean notes, snippets, shell scripts that test for the presence of a particular bug, ideas, etc.) If it’s in the same folder as the actual git repo, it shows up in diffs, might accidentally get committed, etc. If I don’t keep it in the same folder as the git repo, it wanders the wasteland of my hard drive and gets lost.

Where I keep my scratwork right now, is I do this:

  1. Create and configure a global gitignore file.
  2. Put a distinctive directory name in there, like DevScratch.
  3. In all my local repos, create a directory called DevScratch.
  4. Scratchwork goes in DevScratch.
  5. Profit.

Benefits

This approach has a few advantages:

The main drawback I’ve found is that I sometimes accidentally match a file glob from the parent repo. For example, if something in DevScratch matches test_*.py, it might get invoked by the unit test runner. For that reason, I have a tendancy for everything in DevScratch either to be a shell script, or to be a markdown file with code snippets in it. My absolute favorite thing to put in the DevScratch folder is a single shell script called repro.sh that reproduces the bug I’m currently trying to fix, but that idea deserves its own post.

So the next time you need to take temporary notes about a complex bug you’re trying to fix, or write little shell scripts to check on things, but that definitely shouldn’t be committed to the main repo, consider adding them to a globally gitignored scratchwork folder.

Till next week, happy learning!
– Will

Discussion

Love this post? Hate it? Is someone wrong on the internet? Is it me? Please feel free to @me on mastodon

I used to host comments on the blog, but have recently stopped. Previously posted comments will still appear, but for new ones please use the mastodon link above.

Join the conversation!