Writing git commit messages should be done inside your editor because it allows you to add a lengthier commit description, as opposed to git commit -m which just puts everything as the first line.

Well if your editor of choice is Vim, this is what happens after you enter git commit.

Notice how first 50 chars of a commit message are highlighted in red. This is used to notify you about the length of the first line of a commit message so you know when it's too lengthy. For Vim, 50 chars is the suggested size of the first line of commit message.

Well this isn't a good default for me, since the only thing that's worrying me is the truncation of the first line of commit message when my code ends up on Github. I'm only interested if the first line of my commit message is short enough to be displayed in full on Github.

If that's not the case I'll end up with something like this.

Yuck.

Preventing this is easy. Just make Vim highlight the first 72 chars in red, which is the maximum number of characters Github allows in the first line.

In order to do so, alter Vim's syntax rules for git commit messages, by editing ~/.vim/after/syntax/gitcommit.vim like this.

syn clear gitcommitSummary
syn match gitcommitSummary    "^.\{0,72\}" contained containedin=gitcommitFirstLine nextgroup=gitcommitOverflow contains=@Spell

This will make Vim look like this.

Now you'll be notified if you cross the length limit for the first line of git commit message on Github and you'll know exactly where it starts truncating it.

Friends don't let friends over the Github char limit.

Written by

Hrvoje Šimić

@shime_sh