Writing Commit Messages

I’ve recently started working at a startup company in New York City (read: four days) and as a new Software Engineer to the team, I’ve been thinking about the good practices I want to put in place for myself and the engineers who start after me — to make their on-boarding process easier. Today, I had to commit a few minor changes I’d made along with the assistance of my Tech Lead, to the product I’m going to be working on over the coming months.

In the past, I’ve written commit messages using what I thought was a standard format:

$ git add .
$ git commit -m "initial commit"
$ git push origin <branch name>

On one of the many on-site job interviews over the past two months, I learned about a different method of committing code. First, commit each file individually, then:

$ git add app.js
$ git commit

That’s it! This command opens up vim editor where you write your commit message. If you’re not used to vim, this part might be a bit tricky but just follow me :-)

  1. Press the letter i to enter insert mode

  2. Start typing the title of your commit message

  3. Once completed, hit ESC

  4. Finally, press :wq to save the file and exit the editor

When writing a commit message, convention is to summarize the entire commit on the first line in less than 50 characters, leave a blank line, then a detailed explanation of what’s been changed.