Command-line interface for linting commit messages with comprehensive options for different use cases including git hooks, CI/CD integration, and interactive usage.
The primary commitlint command lints commit messages against configured rules.
commitlint [input] [options]
# Examples:
commitlint # Read from .git/COMMIT_EDITMSG
echo 'feat: add feature' | commitlint # Read from stdin
commitlint --edit .git/COMMIT_EDITMSG # Read from file
commitlint --from HEAD~1 --to HEAD # Lint commit rangeControl how commitlint loads and applies configuration.
--config, -g <path> # Path to configuration file
--print-config [format] # Print resolved config ('', 'text', 'json')
--extends, -x <preset> # Shareable configurations to extend (array)
--parser-preset, -p <name> # Parser preset for conventional-commits-parserUsage Examples:
# Use custom config file
commitlint --config ./custom-commitlint.config.js
# Print resolved configuration as JSON
commitlint --print-config json
# Extend multiple configurations
commitlint --extends @commitlint/config-conventional --extends @commitlint/config-lerna-scopes
# Use custom parser preset
commitlint --parser-preset conventionalcommitsSpecify where commitlint should read commit messages from.
--edit, -e [file] # Read from commit file or .git/COMMIT_EDITMSG
--env, -E <variable> # Read from environment variable
--from, -f <ref> # Lower commit range
--to, -t <ref> # Upper commit range
--git-log-args <args> # Additional git log arguments as space separated stringUsage Examples:
# Read from git commit message file (git hooks)
commitlint --edit $1
# Read from environment variable
commitlint --env COMMIT_MESSAGE
# Lint commits in range
commitlint --from HEAD~5 --to HEAD
# Lint commits with additional git log args
commitlint --from HEAD~1 --git-log-args="--merges"Control how commitlint displays results and errors.
--format, -o <format> # Output format
--color, -c # Toggle colored output (boolean, default: true)
--quiet, -q # Toggle console output (boolean, default: false)
--verbose, -V # Enable verbose output (boolean)
--help-url, -H <url> # Help URL in error messageUsage Examples:
# Disable colored output
commitlint --no-color
# Silent mode (no output unless errors)
commitlint --quiet
# Verbose output with detailed information
commitlint --verbose
# Custom help URL in error messages
commitlint --help-url "https://example.com/commit-guidelines"Control how commitlint behaves and reports results.
--cwd, -d <directory> # Directory to execute in (default: cwd)
--strict, -s # Strict mode - exit code 2 for warnings, 3 for errors
--version, -v # Display version information
--help, -h # Display helpUsage Examples:
# Run in specific directory
commitlint --cwd /path/to/project
# Strict mode with different exit codes
commitlint --strictSpecialized command for Travis CI environments.
commitlint-travis [options]
# Automatically detects and lints relevant commits for PRs
# Uses same options as main commitlint commandInteractive commit message creation with validation.
commit [options]
# Prompts for commit message components
# Validates against commitlint configuration
# Generates properly formatted commit messages# Normal mode
0 # Success - no issues found
1 # Failure - errors or warnings found
# Strict mode (--strict flag)
0 # Success - no issues found
1 # Failure - unrelated errors
2 # Warnings found
3 # Errors found# Install as commit-msg hook
echo 'npx --no -- commitlint --edit "$1"' > .git/hooks/commit-msg
chmod +x .git/hooks/commit-msg
# With Husky
npx husky add .husky/commit-msg 'npx --no-install commitlint --edit "$1"'# GitHub Actions / CI environments
commitlint --from HEAD~1 --to HEAD --verbose
# Travis CI (using specialized command)
commitlint-travis --verbose
# With specific configuration
commitlint --config .commitlintrc.json --from $CI_COMMIT_BEFORE_SHA --to $CI_COMMIT_SHA# Quick lint of current commit message
git log -1 --pretty=format:"%s" | commitlint
# Lint recent commits
commitlint --from HEAD~5
# Lint with verbose output for debugging
commitlint --verbose --from HEAD~1# Print resolved configuration
commitlint --print-config json
# Test with different extends
commitlint --extends @commitlint/config-angular --print-config
# Validate configuration works
echo "feat: test message" | commitlint --config ./test-config.js