Published at
Updated at
Reading time
This post is part of my Today I learned series in which I share all my web development learnings.

When you use git on the command line you might have used the message flag (-m). It allows developers to define commit messages inline when calling git commit.

git commit -m "my commit message"

I'm not the biggest fan of this approach because I prefer to edit the commit message in vim (which I only use for writing commit messages). It gives me the opportunity to double-check the files I'm committing.

Today I learned that the git commit command accepts multiple message flags. ๐Ÿ˜ฒ

It turns out that you can use the -m option multiple times. The git documentation includes the following paragraph:

If multiple -m options are given, their values are concatenated as separate paragraphs

If you run the following command

git co -m "commit title" -m "commit description"

it will result in this commit.

Author: stefan judis <>
Date:   Tue Jul 7 21:53:21 2020 +0200

    commit title

    commit description

 test.txt | 0
 1 file changed, 0 insertions(+), 0 deletions(-)

You can use multiple -m flags to create "multiline commits", and I have to admit that this can be very handy in some cases.

Edited: Several people pointed out that you can achieve the same commit structure including a title and body (multiple lines) by opening quotes, pressing enter and closing the commit with quotes again.

git commit -m "commit title
> commit description"
[master 2fe1ef8] commit title
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 test-2.txt

If you want to see this command in action, I shared a short terminal session on Twitter with a little video.

And thanks to Stephan Schneider who shared that little git tip in our company slack. ๐Ÿ™‡โ€โ™‚๏ธ

Was this TIL post helpful?
Yes? Cool! You might want to check out Web Weekly for more quick learnings. The last edition went out 4 days ago.
Stefan standing in the park in front of a green background

About Stefan Judis

Frontend nerd with over ten years of experience, freelance dev, "Today I Learned" blogger, conference speaker, and Open Source maintainer.

Related Topics

Related Articles