Skip to content

Instantly share code, notes, and snippets.

@starise
Last active April 14, 2022 21:06
Show Gist options
  • Save starise/f7adbf92fed7df35d37ee0afc39eaa0f to your computer and use it in GitHub Desktop.
Save starise/f7adbf92fed7df35d37ee0afc39eaa0f to your computer and use it in GitHub Desktop.
Prepare a new project to be conventional commit ready

Conventional Commit

Prepare a repository to be conventional commit ready with:

  • commitlint - Lint commit messages
  • husky - Modern native git hooks made easy
  • commitizen - Prompt to fill out required fields at commit time

commitlint

# Installation
npm install @commitlint/{cli,config-conventional} --save-dev

# Configuration
echo "module.exports = { extends: [\"@commitlint/config-conventional\"] };" > commitlint.config.js

husky

# Installation
npm install husky --save-dev

# Enable git hooks
npx husky install

# Git hooks enabled after install
npm set-script prepare "husky install"

# Git commit can use git cz hook
npx husky add .husky/prepare-commit-msg "exec < /dev/tty && git cz --hook || true"

# Add commitlint in husky
npx husky add .husky/commit-msg 'npx --no-install commitlint --edit'
sed 's/--edit/--edit $1/g' -i .husky/commit-msg

commitizen

# Installation
npm install commitizen --save-dev

# Make project use cz-conventional-changelog adapter
commitizen init cz-conventional-changelog --save-dev --save-exact

Usage

Use git commit or git cz or cz or cz commit to commit.

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