DEV Community

Mat
Mat

Posted on • Edited on

2

How to automatically add stuff to git messages

Did you know you can customise the default git message template?

First create a file, ~/.gitmessage.

Then run git config --global commit.template ~/.gitmessage.

Whatever you put in that file will be the default text opened in your editor when you start a commit message.

I found this useful because as a technical lead, I spend most of my coding time pair programming. Github has a nice feature where you can add co-authors to your commits. So my template contains a few Co-authored-by lines for people I work with, like this:

Co-authored-by: Fox Mulder <fox.mulder@fbi.gov>
Co-authored-by: Dana Scully <dana.scully@fbi.gov>
Enter fullscreen mode Exit fullscreen mode

This way, I can quickly delete the lines I don't need when I write the message, rather than writing the Co-authored-by from scratch each time.

These lines are called "trailers" and go at the end of the message. They are not standardised but there are various tools which interpret them.

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

Top comments (0)

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay