Part of a Series on Habits That One Can Only Learn The Hard Way

multiple looms warped together and wrapped around the deck of a warehouse
Multiple looms warped together and wrapped around the deck of a warehouse

Everyone who already knows what branch sanitizing is, move along. There are plenty of other stories you can chuckle at knowingly and stroke your beard before dropping the wisdom of the ancients on youngsters who haven’t any sense and won’t listen anyway.

For everyone that’s left, let’s step back. Proper version control is why people get in the habit of committing to git on their way out during a fire.

Git Commit

Git is one of the most popular version control tools out there, and it works like this. A file is added to a watched directory. The first time the file is committed to git, the entire file is saved. On all subsequent commits, the difference between the last commit and the current commit is what’s saved. This is why the relationship between the size of a repository and the size on disk of the actual code is casual at best, because you’re not just storing the code in text. Behind the scenes, git is a database of every change it took to get from that first file to how the file is today.

Now, we’re used to time being one-dimensional. There are a few creative tools that allow one to move backwards and forwards through time using redo and undo functions, but for the most part we don’t have access to moving sideways through time, jumping between various choices, unless we save a copy of a file and have a bunch of revision names. Even then, the actual implementation is kludge-y at best.

Conflux: Harvest Moon by Tuyen My Nguyen & Pamela Wilson

It wasn’t until I walked through these looms warped together in space that had a hope of visualizing how this multidimensional timeline worked, branching out based on choices. Harvest Moon is a single plane of threads, and work in a project depends on a single outcome. But the plane, nor the process, need to be linear to arrive at that point.

Git branches allow you to mark a point at which you might try something different, and come back to that point. The main branch is the branch that everyone wants to be nice. During a production deployment, this is the branch that will be copied onto the servers that your operations team is managing and your users expect dependable services from, so it’s important to be able to make changes while protecting this copy of the code from solutions that aren’t ready yet.

If you find yourself wanting to go backwards in time to a safe spot on your same branch, you are likely to get yourself into some trouble. You can create circular or frayed git timelines in your quest to revert to the commit you remember, or even worse you might discover that somehow a commit you swear you remember making might have been deleted while you were learning how to revert things. You may need to spend all weekend or longer teasing apart the threads of time and combing out the snarls, so that the loom of the work may weave ever onwards.

The proper way to use git branches is to treat them as disposable, and create them for each new part of the whole that will need to be changed. These feature or bug fix branches should strive to be as close to the original as possible, to limit how much conflict there will be at the point the branch is merged back into the trunk (or plane).

Then, you can simply delete a branch or only have a couple of commits to deal with reverting if issues arrive.

In the end, while I didn’t think much of how prescient it was that I was able to see this artwork at the time, it was only a couple of weeks later that being able to visualize this space came in handy for figuring out how to manually assemble a new clean copy of code from small pieces scattered across multiple reverted commits. (As an aside, this has also proven helpful for being able to visualize component scope in React.) And I hope to keep good habits going forward so I never have to do that again.

I’ll warn you, but you won’t really learn until you experience it yourself. Branch hygiene is important, and if a senior developer tells you that your git process is warped, they may be thinking back to when they were fresh and young and had to pick out the threads of time themselves.

Word Count Plugin:


Related Posts