Git better—learn to rewrite history like it’s 1984

By Deiwin Sarjas

When working on a problem, you want to commit early and commit often. This ensures that you don’t lose your work and it allows you to backtrack incrementally as you try various approaches. You don’t want style guides to distract you from the task at hand.

However, after you’ve solved the problem and are happy with the result you will likely need to clean up your initial quick-and-dirty commits. Many teams and projects require you to structure your commits and their messages in a certain way. We stick to these Four Rules for Effective Collaboration, for example.

You can think of a list of commits as a proof (or an argument) of sorts.

The order in which we work out the details of the argument may be very different from the order in which we invented them; and the order in which we write down the details in a definitive exposition may be still different.
- Polya, G.. How to Solve It (p. 69)

Gojo is a small set of git exercises bound together by a silly story about shopping lists, a snowboarding accident, and amnesia. A portmanteau of git and dōjō (a hall or space for immersive learning or meditation), it provides a safe space for you to practice rewriting git history.

A kendō dōjō. Wang Ming, via Wikimedia Commons.

Gojo assumes you are already comfortable with basic branch, staging area, and commit management. These exercises help you practice more advanced operations, such as changing, splitting, and combining different commits and recovering code you think you’ve lost.

You can use these exercises to practice alone, but if at all possible, I recommend doing it with a larger group.

For example, I scheduled a meeting area for an hour and a half and invited others to join me to practice git. 12 people joined. I split people into pairs at random and instructed every pair to go through these exercises one by one.

Every pair was meant to complete every exercise at least twice. Why twice? Well, I asked every pair to have a “driver” and a “navigator”. Everyone had to complete every exercise as a driver at least once. Additionally, if someone completed a problem but it didn’t go very smoothly, then they were supposed to start over. The idea was to repeat until these things became comfortable.

People who were less experienced learned a lot from their partners and those who were more experienced had a chance to solidify their ideas by explaining them.

The driver/navigator separation forced people to learn from each other. Drivers weren’t supposed to do anything that their navigator had not instructed them to. This proved to be very helpful. People who were used to doing things in different ways learned about alternatives and discussed their merits. People who were less experienced learned a lot from their partners and those who were more experienced had a chance to solidify their ideas by explaining them.

The exercises do not prescribe any particular method for solving the problems. Whatever feels most comfortable to you and makes the tests pass is a good solution. This is also why I recommend working on these in pairs as described above — you get better by learning about alternative paths taken by other people.

So what are you waiting for? Check out the exercises and instructions on GitHub @ salemove/gojo and start practicing!