why should I commit frequently?

Frustration

Every now and then I see developers making commits of huge size – sometimes 1000s of lines(the above image is from a real incident where one developer added 1000+ lines and deleted 450+ lines in a single commit). Even I have done this mistake multiple times. This small post is my take on why should we commit frequently. At the end of the post, I am going to show a small tool which can help you in building the habit of committing frequently.

Importance of committing frequently ?

  • Having periodic checkpoints because of small commits helps in debugging and makes the history cleaner
  • Small commits make collaboration better. If you commit and push the changes frequently, your team-mates will be able to integrate with your codebase frequently(sometimes even prevent merge conflicts)
  • Small commits encourages us to think iteratively

A plugin to build your habit

If you use zsh, you can use this plugin to encourage the best practises of git. The plugin displays a message in the command prompt when it sees that there are some uncommitted changes. See the image below – the plugin is showing Don’t forget to commit frequently in the command prompt.