Skip to content

Instantly share code, notes, and snippets.

@santoshpy
Last active October 14, 2018 10:36
Show Gist options
  • Save santoshpy/69e0418e0a5745b6edc94b6ffd4538f9 to your computer and use it in GitHub Desktop.
Save santoshpy/69e0418e0a5745b6edc94b6ffd4538f9 to your computer and use it in GitHub Desktop.
How to write git commit message

How to Write a Git Commit Message


It is useful to write good commit message which shows professionalism. it shows whether a developer is a good collaborator or not?

The most basic element of keeping a healthy commit history: How to write a great commit message.

Just follow the seven rules below and you’re on your way to committing like a pro.

1. Separate subject from body with a blank line

Though not required, it’s a good idea to begin the commit message with a single short (less than 50 character) line summarizing the change, followed by a blank line and then a more thorough description. The text up to the first blank line in a commit message is treated as the commit title, and that title is used throughout Git.

2. Limit the subject line to 50 characters

  • So shoot for 50 characters, but consider 72 the hard limit.

3. Capitalize the subject line

  • This is as simple as it sounds. Begin all subject lines with a capital letter.

For example:

+ Accelerate to 88 miles per hour

Instead of:

- accelerate to 88 miles per hour

4. Do not end the subject line with a period

Trailing punctuation is unnecessary in subject lines. Besides, space is precious when you’re trying to keep them to 50 chars or less.

Example:

+ Open the pod bay doors

Instead of:

- Open the pod bay doors.

5. Use the imperative mood in the subject line

Imperative mood just means “spoken or written as if giving a command or instruction”. A few examples:

  • Clean your room
  • Close the door
  • Take out the trash

Git itself uses the imperative whenever it creates a commit on your behalf.

So when you write your commit messages in the imperative, you’re following Git’s own built-in conventions. For example:

+ Refactor subsystem X for readability
+ Update getting started documentation
+ Remove deprecated methods
+ Release version 1.0.0
+ merge pull request #123 from user/branch

Insted of:

- Fixed bug with Y
- Changing behavior of X
- More fixes for broken stuff
- Sweet new API methods

Remember: Use of the imperative is important only in the subject line. You can relax this restriction when you’re writing the body.

6. Wrap the body at 72 characters

The recommendation is to do this at 72 characters, so that Git has plenty of room to indent text while still keeping everything under 80 characters overall.

7. Use the body to explain what and why vs. how

In most cases, you can leave out details about how a change has been made. Code is generally self-explanatory in this regard (and if the code is so complex that it needs to be explained in prose, that’s what source comments are for). Just focus on making clear the reasons why you made the change in the first place—the way things worked before the change (and what was wrong with that), the way they work now, and why you decided to solve it the way you did.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment