Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save Masihtabaei/b7fcd19058b69597f21a203313d96e4b to your computer and use it in GitHub Desktop.

Select an option

Save Masihtabaei/b7fcd19058b69597f21a203313d96e4b to your computer and use it in GitHub Desktop.
Guide for using local pre-commit automatic validation of commit messages following rules of the Conventional Commits

Local Pre-commit Automatic Validation for Conventioanl Commit Messages: Usage

What is this?

This guide will help you activate local automatic validation of commit messages using the Conventional Commits format. It is intended for those who will clone repositories that are already set up with Git hooks, the pre-commit framework, and the git-conventional-commits package.

How to Activate It?

  1. Check for pre-commit Installation

After cloning the repository, check if pre-commit is installed on your machine by running the following command:

> pre-commit --version

If you get an error, you’ll need to install pre-commit first. You can do this by running (requires both python and pip):

> pip install pre-commit

Once installed, verify by running the same command again:

> pre-commit --version
  1. Install Git Hook

Next, navigate to the root directory of your cloned repository and run the following command to install the commit-msg hook:

> pre-commit install -t commit-msg

You're Done!

Now you're all set! The pre-commit hook will automatically validate your commit messages to ensure they follow the Conventional Commits format. Try making some changes (e.g., adding a new feature 😎 or fixing a bug 😨), stage them, and then commit. The hook will check your commit message, and if it doesn't follow the proper convention, it will reject the commit.

Her you can see an example for a successful validation:

image

And here for a unsuccessful one:

image

Have fun :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment