# 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:

```git
# Commit title - 50 characters ------------------|


# Commit body - Line Width 72 characters ------------------------------|


# References, issue #, ticket #, etc:


# Any co-authors:
# Co-authored-by: LastName, FirstName <email@email.com>

```

_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](https://cdn.hashnode.com/res/hashnode/image/upload/v1631937446887/dJZTE65Lh.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:
- https://chris.beams.io/posts/git-commit/

A more in-depth guide about git commit templates:
- https://gist.github.com/lisawolderiksen/a7b99d94c92c6671181611be1641c733




