This guide provides detailed instructions for setting up and using the commit management tools in your projects.
- Git version 2.0 or higher
- Python 3.6 or higher (for pre-commit framework)
- Bash shell (for commit message validation script)
# Using Homebrew
brew install pre-commit
# Using pip
pip install pre-commit# Using pip
pip install pre-commit
# Using apt (if available)
sudo apt install pre-commit# Using pip
pip install pre-commit
# Using chocolatey
choco install pre-commitpre-commit --versionCreate a .pre-commit-config.yaml file in your project root:
repos:
- repo: https://github.com/Gosayram/commit-mgmt
rev: main # or specific version tag
hooks:
- id: commit-msg-format# Install commit-msg hook
pre-commit install --hook-type commit-msg
# Install pre-commit hook (if you have other hooks)
pre-commit install
# Install all hook types
pre-commit install --install-hooksTest with a sample commit message:
# Create a test file
echo "test" > test.txt
git add test.txt
# Try committing with correct format
git commit -m "[TEST] - verify commit message validation"
# Try committing with incorrect format (should fail)
git commit -m "invalid commit message"For production environments, always pin to specific versions:
repos:
- repo: https://github.com/Gosayram/commit-mgmt
rev: v1.0.0 # specific version tag
hooks:
- id: commit-msg-formatrepos:
- repo: https://github.com/Gosayram/commit-mgmt
rev: main
hooks:
- id: commit-msg-format
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yamlrepos:
- repo: https://github.com/Gosayram/commit-mgmt
rev: main
hooks:
- id: commit-msg-format
- repo: https://github.com/psf/black
rev: 23.3.0
hooks:
- id: black
- repo: https://github.com/pycqa/isort
rev: 5.12.0
hooks:
- id: isortrepos:
- repo: https://github.com/Gosayram/commit-mgmt
rev: main
hooks:
- id: commit-msg-format
- repo: https://github.com/pre-commit/mirrors-prettier
rev: v3.0.0
hooks:
- id: prettierrepos:
- repo: https://github.com/Gosayram/commit-mgmt
rev: main
hooks:
- id: commit-msg-format
- repo: https://github.com/tekwizely/pre-commit-golang
rev: v1.0.0-beta.5
hooks:
- id: go-fmt
- id: go-imports
- id: go-vet-modCreate a template repository with pre-configured .pre-commit-config.yaml:
- Create a new repository or use existing template
- Add
.pre-commit-config.yamlwith your organization's standards - Include setup instructions in README
- Add to organization templates
Create .github/workflows/pre-commit.yml:
name: Pre-commit
on:
pull_request:
push:
branches: [main]
jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: 3.x
- uses: pre-commit/action@v3.0.0Add to .gitlab-ci.yml:
pre-commit:
image: python:3.9
stage: test
before_script:
- pip install pre-commit
script:
- pre-commit run --all-filesIf you were using local commit message validation:
# Remove local script
rm scripts/check-commit-msg.sh
# Update .pre-commit-config.yaml
# Remove local repo configuration
# Add remote repo configurationReplace local repo configuration:
# OLD - Local configuration
repos:
- repo: local
hooks:
- id: custom-commit-msg
name: Custom Commit Format
entry: scripts/check-commit-msg.sh
language: script
stages: [commit-msg]
# NEW - Remote configuration
repos:
- repo: https://github.com/Gosayram/commit-mgmt
rev: main
hooks:
- id: commit-msg-format# Uninstall old hooks
pre-commit uninstall
# Install new hooks
pre-commit install --hook-type commit-msg# Check if hooks are installed
ls -la .git/hooks/
# Reinstall hooks
pre-commit install --hook-type commit-msg# Fix file permissions
chmod +x .git/hooks/commit-msg# Update hooks manually
pre-commit autoupdate
# Clear cache
pre-commit clean# Check current configuration
pre-commit --version
# Update pre-commit
pip install --upgrade pre-commit# Test specific hook
pre-commit run commit-msg-format --hook-stage commit-msg
# Test with sample message
echo "[TEST] - sample message" | pre-commit run commit-msg-format --hook-stage commit-msg# Run with verbose output
pre-commit run --verbose commit-msg-format --hook-stage commit-msg# Validate configuration file
pre-commit validate-config
# Show configuration
cat .pre-commit-config.yaml- Always pin to specific versions in production
- Test new versions in development environments first
- Use semantic versioning for your own pre-commit configurations
- Document setup process in your README
- Provide example configurations for different project types
- Include troubleshooting steps for common issues
- Consider organization-wide pre-commit configuration templates
- Regularly update hook versions
- Monitor hook performance impact
- Review and update commit message standards as needed
- Collect feedback from team members