A commit template helps to write better commits that are more concise and standardised.
Typically a commit may contain a header, a body and a footer.
For example
The key point to note here is that the #
symbol denotes a comment
So for the below commit template, it is only an outline, and can include any text that you like.
Feel free to customise this template and make it your own đ
1link
2link# ----------------------------------------------------------
3link# Header - type(scope): Brief description
4link# ----------------------------------------------------------
5link# * feat A new feature - SemVar PATCH
6link# * fix A bug fix - SemVar MINOR
7link# * BREAKING CHANGE Breaking API change - SemVar MAJOR
8link# * docs Change to documentation only
9link# * style Change to style (whitespace, etc.)
10link# * refactor Change not related to a bug or feat
11link# * perf Change that affects performance
12link# * test Change that adds/modifies tests
13link# * build Change to build system
14link# * ci Change to CI pipeline/workflow
15link# * chore General tooling/config/min refactor
16link# ----------------------------------------------------------
17link
18link
19link# ----------------------------------------------------------
20link# Body - More description, if necessary
21link# ----------------------------------------------------------
22link# * Motivation behind changes, more detail into how
23link# functionality might be affected, etc.
24link# ----------------------------------------------------------
25link
26link
27link# ----------------------------------------------------------
28link# Footer - Associated issues, PRs, etc.
29link# ----------------------------------------------------------
30link# * Ex: Resolves Issue #207, see PR #15, etc.
31link# ----------------------------------------------------------
To add the template to your global git config enter the following:
1linkgit config --global commit.template path/to/your/file.txt
Now whenever youâre making a commit, instead of the typical git commit -m "A brief commit message", just enter git commit to open your default editor with the template in place. Youâll automatically have a guide to choose conventions from to create a structured message.
The âheaderâ of the commit message notes the type of the commit as docs and a brief description that does not exceed 60 characters to ensure readability (the commented lines are 60 characters long and act as guides for when to use a line break). The âbodyâ optionally elaborates on the changes made, and the âfooterâ optionally notes any issue/PR the commit is related to. The final message will simply look like this:
The final message will look like this
1linkdocs: Update README with contributing instructions
2link
3linkAdds a CONTRIBUTING.md with PR best practices, code style
4linkguide, and code of conduct for contributors.
5link
6linkCloses #9
If you use Vim or Neovim, and you want to speed up the process even more, you can add this to your git config:
1link# Neovim
2linkgit config --global core.editor "nvim +16 +startinsert"
3link
4link# Vim
5linkgit config --global core.editor "vim +16 +startinsert"
This sets the default editor to Neovim (or Vim), and places the cursor on line 16 in Insert Mode as soon the editor opens. Now whenever youâre committing, when you type git commit, Neovim opens the template, places your cursor, and accepts typing input immediately. Also note that you can still use git commit -m "Your message" exactly as you did before, but the configuration will default to the template setup when you just type git commit.
Home Backstory Why Git? Setting Up GitHub GitHub CLI Your GitHub Profile GitHub Pages Creating A New Repo Cloning A Repository Your First Commit Ignoring Files In Git Stashing Your Changes Branching With Git Merging Git Branches Rebasing Vs Merging Git Workflows Fork And Pull Flow Your First Pull Request Automated Security Alerts Seeing The Differences Removing/Deleting Files Reverting Your Commits Configuring your Git Commit Templates Creating Shortcuts Dotfile Management Sponsoring Open Source Handy Commands Thank You