Code with Goals: git+commitlint

Daniel Tan
GlassBlade
Published in
2 min readMay 2, 2020

Discipline is the bridge between the goals and accomplishment.
— Jim Rohn

Git is a software tool to manage version history of text. Similar tools include Subversion and Perforce. Subversion has been basically eliminated by the times as it is unsuitable for rapid iterative development due to having only basic merging capability and low performance. On the other hand, Perforce is not free, has a complicated work-flow, and involves more communication to use, so it is not as popular as Git.

When used with some other automation software, Git can play the role of conflict management, project progress management, code quality improvement, self-motivation, and promotion of continuous learning within the team.

The first magical combination of automation tools I will be introducing today is precommit and commitlint. If you want to skip to the installation steps it’s available at the end.

Commitlint

When writing code, it is easy to enter a so-called “flow state”, but chaotic thought processes usually results in substandard git commit messages, like git commit -m "update", greatly reducing team collaboration and the ability to determine problems rapidly, a.k.a. “fail fast”. This will reduce work efficiency and will obscure your contribution of the project.

commitlint standardises git commit messages, allowing the team to clearly see your contribution in the git history, and facilitate team collaboration.

The way it works is to using git hooks to check your commit message before you submit. If you don’t pass the specification, you will be rejected.

Example failing demonstration:

git commit -m “update”

Example commitlint demonstration:

git commit -m “feat: create interfaces for hero classes”

The general specifications of commitlint can be referred to here.

Precommit

precommit automatically manages and installs git hooks for you. The example below also includes an installation of commitlint. Some people will suggest husky, but husky can only be applied in npm projects, while precommit has no such restriction.

1. Create a new document in the root folder of your project, called .pre-commit-config.yaml. This will be the configuration of precommit. The content is as follows:

repos:
— repo: https://github.com/alessandrojcm/commitlint-pre-commit-hook
rev: v2.2.0
hooks:
-id: commitlint
stages: [commit-msg]
additional_dependencies: [‘@ commitlint / config-conventional’]

2. Create a new document in the root folder of your project, called commitlintrc.yaml. This is the configuration of commitlint. The content is as follows:

extends:
-‘@ commitlint / config-conventional’

3. In the terminal, go to the root folder of the project and execute the following commands:

pip install pre-commit
pre-commit install — hook-type commit-msg
pre-commit install

I try to update weekly. The next post would be about Gitlab and Kanban boards.

--

--