Micro commit approach in Git

Before talking about the micro commit approach in Git, let me tell you an exciting story. The documentary Free Solo is the story of the 8-year effort of Alex Honnold, the famous American rock climber, to free solo climb the El Capitan wall. There have not been many safe ascents of this 914m vertical rock, let alone a free solo! Free solo refers to climbing without ropes, hooks, and other equipment and relying only on one’s strength and skills. In other words, the ascendant’s first mistake will be his last. Frisolo’s ascent on such a route is undoubtedly the mountaineering miracle of the century. Honnold committed to taking one step at a time to accomplish this challenging climb.

Alex Honnold has climbed the rock repeatedly using ropes and safety equipment in preparation for his free solo ascent of El Capitan. He uses different ropes and hooks in all training climbs. With this, he makes a fatal and dangerous jump in a relatively safe way, and if he makes a mistake, he returns to the same place with the help of ropes and tries again, just like savepoints in computer games.

This article is about the micro commit approach in Git! When you make many changes to your code, like Alex Hannold, you can pin your code in one place and create multiple savepoints to avoid disaster and easily roll back to previous versions of your code that worked.

Micro commit

In his dangerous ascent, Alex Honnold was trying to go from one point to another with very short steps. This technique also applies to code editing. To edit code, you need to take small, conscious steps and go ahead and commit the changes to Git every time the code compiles without any errors. In addition, you should move so that the distance between two commits is as small as possible. Tim Ottinger calls this a micro-commit.

Micro commit approach in Git
As part of a git log, note the commit times

Whichever way you decide to edit your code, choose the path with the shortest steps. Most people do not understand the importance of this issue. They start programming and, hours later commit to Git to save a version. Why jump high when you can make small, controlled movements?

When you submit a big change to Git to implement a feature or fix a bug, you completely hide the step-by-step process by which you get the final solution. A well-written set of micro commits can provide a step-by-step story and process of your code changes to future reviewers.

See also  How to stay motivated as a remote developer

On the other hand, to tell a coherent story through commits, you need to organize them properly. Each commit should be an independent step towards a new feature or bug fix. It’s a very good practice to break down a complex solution into a defined sequence of code changes, leading to more streamlined development practices.

Step-by-step coding with Git

Git has more capabilities and potential than what is imagined. Developers commonly use Git to coordinate their work with others. Therefore, they only use Git when needed, which is usually limited to the git pull and git push commands.

However, a good coding strategy is to commit at short intervals when editing your code. You can always return to the last saved point and start with a clean code snippet. With Git, you can do trial and error; you can try one path, and if you hit a dead end, go back and try another. Just commit your changes step by step, go back to a previous save point and try another path.

With micro commits, instead of an uncertain, ill-planned, aimless movement, we can move forward in small steps while still having several points of return, just like Alex Honnold, who climbed the mountain with equipment like rope and hook.

Was this helpful?
[0]

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top