The Time Git Ignore Made Me Cry*

My very first week at DevMynd(custom software development services) a co-worker introduced me the power of using the global .gitignore file. Fresh out of Dev Bootcamp, I was excited about everything but this really blew my slippers off.

Git says, “a gitignore file specifies intentionally untracked files that Git should ignore.” (Dang, that is a really well named file!) Documentation continues, “Each line in a gitignore file specifies a pattern. When deciding whether to ignore a path, Git normally checks gitignore patterns from multiple sources….”

One source that Git checks is a project specific .gitignore. This file lives in a project’s root directory and is shared between the development team. Ruby on Rails projects are created with a .gitignore file!

Another source is in your home directory, the .gitignore that made me cry. For the past year and a half my global .gitignore has looked like this:

.DS_Store
.sass-cache
*.swp

notes

In the top three lines I ignore a few of the classic directories that I don’t want to track (some operating system files, compiled sass and temporary vim files). These are recommended patterns to ignore. My problem begins on the last line. I’ve added a very broad reference to something called `notes`. In every project I’ve worked on I will run touch notes  in the directory, and take notes in it! Because it is globally git ignored, I don’t have to worry about committing personal questions, reminders, and general babble that I want to save for myself.

It has worked beautifully!

Until the day I encountered a schema with a Notes table. On this fateful day, my co-worker and I were pairing on my machine, making basic CRUD actions for the application’s note taking feature. The model already existed, so we wrote some tests, setup the controller actions, made a gorgeous form and a page to display a list of notes with all of the action links readily available. Localhost looks stunning, as perfect a CRUD as you could imagine.

Then WABAM! I go to commit and check  git status and things are missing. We check the file paths, all good. We reset the terminal, all good. Panic rises. Is something wrong with my computer? Am I losing my mind? HOW DO WE GO ON? My pair turns to me, “This is so weird. Why aren’t all of the files getting tracked? Do you have some custom configuration that is blocking us?” A single, shining tear of relief falls from my eye. I’m not going insane and my computer isn’t broken! In fact, everything is working exactly as I told it to. We open my global .gitignore, spot the culprit, and immediately change “notes” to “sashanotes”.

I need a pattern that I can guarantee won’t be generated elsewhere. Giving the pattern an extension like “notes.md” would also fix my current problem but that’s not as fun. Now, as long as I don’t have a join table of my name and a notes model, I am free to run  touch sashanotes and go on living my life.

Moral of the story: understand your tools. If something works well for you, know how to 1) make it better and 2) fix it if it breaks!

Do not let that customization affect a project because it might make everyone cry. And always be aware of naming things properly.

If anyone has different methods of safe note-taking, I’d love to hear them!

For more information about gitignore, checkout the git docs || the github docs!

* Dramatization: No actual tears were shed in the making this post.
Sasha is a member of DevMynd’s software engineering team focusing on mobile apps and web development. She has been with the company since 2015.