Skip to content

git commit best practices

Abdullah Bakhach edited this page Feb 18, 2017 · 3 revisions

Contents of subject line vs message and JIRA

Basically our git commits have to be well integrated with JIRA so that we can track which task a git commit is made for, how many hours were spent in each commit.. and other things. A git commit can also automatically close a task and do other nifty things.

However with great power comes great responsibility. Git, by definition, is a source control program. It's job is to make it easy to integrate work from multiple developers. And so that is the top most priority while doing anything with git. Without going too far into how and why, the git community asserts that a commit subject line should not be longer than 50 characters.. in other words.. it has to be very short.

that leaves little room for special keywords for integration tools (such as task name, and other actions). thankfully.. these tools also read the git commit message. That being said, we should add all those special keywords in the commit message, NOT the commit subject line.

In the image below you will see and example of the right way of doing things and example of the wrong way of doing it.

first image

(JP:)

Here's a summary of the accepted standards, as I've been able to determine:

  • The first line should be a summary, 50 characters long or less. There should be no period at the end. It should not include JIRA tags. vi helps you with this:

1 vim 2017-02-18 06-22-38

  • The first line needs to briefly explain both what the commit does, and why it does it.
  • The second line should be blank.
  • After the second line, you can provide as much discussion as you like, wrapped to 72-column-wide paragraphs with blank lines separating the paragraphs.
  • Tool integration code (such as Jira, Crucible, etc.) go at the very bottom.

http://www.slideshare.net/TarinGamberini/commit-messages-goodpractices http://robots.thoughtbot.com/5-useful-tips-for-a-better-commit-message http://stackoverflow.com/questions/2290016/git-commit-messages-50-72-formatting http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html

This document explains how to use the tool integration: https://confluence.atlassian.com/display/FISHEYE/Using+smart+commits

Clone this wiki locally