Scott's Recipes Logo

Use Git from Day 1 Even for Side Projects

A few weeks ago, I was talking to a fellow software engineer and he confessed to me that for his new side project, he wasn’t using git. I was, without question, beyond horrified and he and I had a vicious debate about it.

His point was essentially that he’s the only person touching the code so all he’s going to see is an endless string of commits labeled “latest changes” / “rollup commit” / “new stuff”, etc. And, yes, I get that and I don’t disagree but it still felt wrong to me. I countered with the point that git inherently gives you offsite backup and backup is always, always useful. He then countered with the fact that drives are a lot more reliable than they used to be and how he hasn’t lost data in 15 years. This went on and on – it was one of those arguments you have with a fellow nerd of the form irresistible force, meet immovable object.

We finally ended up agreeing that we should simply move on since neither of us was willing to yield.

Today, happily, I had something happen which further convinces me that I’m right. I write a metric ton of side projects because I enjoy building my own tools and I changed into one of them and got this error:

Routing Error
uninitialized constant ProjectsController
Rails.root: /Users/sjohnson/Sync/coding/rails/cartazzi2

Note: This project was a Ruby on Rails based Developer Experience product, I call Cartazzi. Cartazzi organizes all the web based development tooling for working on a web dev project into a single dashboard.

What this was telling me was that my Projects controller simply wasn’t there. This baffled me because this is a shipping product and I hadn’t changed it recently – at least to my knowledge. A quick git status revealed this:

❯ git status
On branch ruby3_2
Changes not staged for commit:
  (use "git add/rm <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
	deleted:    app/controllers/notes_controller.rb
	deleted:    app/controllers/projects_controller.rb      

Yep. For some reason, two of my controllers – Notes and Projects – were simply flat out deleted. Why? I honestly have no idea but I do, vaguely, remember some kind of editor glitch when I was working hard and fast on another bit of code. And, yes, that shouldn’t have deleted code in another project but I do keep everything open all at once and maybe either I was stupid or something stupid happened.

To make a long story short, I simply did:

git checkout -f app/controllers/notes_controller.rb
git checkout -f app/controllers/projects_controller.rb

And, like the arcane magic that is git, the last checked in version of these two files came down from the server and reappeared on my file system.

I’m certain that someone out there is agreeing with my friend and taking the position that I’m in the wrong and this kind of editor glitch (if that’s even what it was) couldn’t happen to them. However, the longer you do this kind of stuff, the more you realize that:

  1. Your code is valuable and needs to be protected – sometimes even from yourself.
  2. You never know what is going to happen. In a long enough career, bad things happen.
  3. Version control exists for a lot of reasons. Not only could version control have given me back an old version of these files that I needed for some reason but it can also do nothing more than give me the latest version of these files.

TLDR

Here’s the TLDR.

  1. Version control is cheap and free.
  2. There’s no damn excuse for not using version control.
  3. If you don’t use version control for everything at all times, you’re some day going to regret it.