This content originally appeared on DEV Community and was authored by Mohamed Saleh
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!
If you wanna learn more aboure git best practices, I think this article explains it well: https://chris.beams.io/posts/git-commit/
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@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.
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
- If you want a more in-depth guides about git commits, check out these amazing write-ups:
This content originally appeared on DEV Community and was authored by Mohamed Saleh

Mohamed Saleh | Sciencx (2021-09-19T17:26:37+00:00) Consistent Git Commit Messages Using a Template. Retrieved from https://www.scien.cx/2021/09/19/consistent-git-commit-messages-using-a-template/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.