Star

Created With

linkSetting Up A Commit Template

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

Screen-Shot-2021-02-11-at-10-26-29-pm.png

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 😀

Instructions
Commit Template
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# ----------------------------------------------------------

linkFor brevity, here are the steps you will need to follow to get set up!

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

linkVim Setup

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.

Setting Up A Commit TemplateYou can find the instructions and link to this file in this Dotfiles repository, which is a neat way to back up your configuration files using GitHubFor brevity, here are the steps you will need to follow to get set up!Vim Setup
Content

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



Developer Student Clubs

logo2.png