Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
September 19, 2021 05:26 pm GMT

Consistent Git Commit Messages Using a Template

One way to improve the consistency of your commits is to use a git template.

Any time you start a new commit, this template will be pre-loaded.

That means you'll be able to use git commit comments with some guidelines and reminders!

This can be useful because it can help remind you of things you typically would include in a git commit message; it could even act as a line length guide!

Note: You don't need to comment out all the contents of your git commit template.

This is simply a common usage but not required... but why would you want all of your commits messages to have the same message?

Usage

First off, in your home directory, create a file with a commonly used name: .gitmessage. <- This is where you'll store the contents of this template.

Here's an example template that I personally use:

# Commit title - 50 characters ------------------|# Commit body - Line Width 72 characters ------------------------------|# References, issue #, ticket #, etc:# Any co-authors:# Co-authored-by: LastName, FirstName <[email protected]>

Note: the line length guides only work for monospaced fonts, i.e., each character has the same width.

I prefer it short and to the point -- but you can include whatever you like in here.

Now, the last step to make it automatically pre-populate your git commit messages is to set it in your git config.

To do it through the command line, run:

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

OR

You can manually set the commit template through your global .gitconfig file.

e.g.: image.png

Wrapping Up

You should be all set!

Now every time you git commit in your project repo, you'll get a pre-loaded template that you can edit for your commit message.

Hope this helps you write better git commits!

References

Learn more about git best practices:

A more in-depth guide about git commit templates:


Original Link: https://dev.to/salehmdev/consistent-git-commit-messages-using-a-template-3ono

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To