Git Hooks
Automatically check code against policies before commits and pushes.Quick Setup
Install MergeGuide git hooks in your repository:mergeguide check on staged changes.
Hook Types
Pre-commit Hook
Runs before each commit, checking staged changes.- Checks only staged files
- Blocks commit if any policy fails
- Shows warnings but allows commit
- Runs quickly (typically < 5 seconds)
Pre-push Hook
Runs before pushing, checking all commits being pushed.- Checks all commits in push range
- More thorough than pre-commit
- Good for catching issues missed locally
Commit-msg Hook
Validates commit message format.- Minimum/maximum length
- Required prefixes (e.g., ticket numbers)
- Conventional commits format
Configuration
Basic Configuration
In.mergeguide.yaml:
Skip Hooks Temporarily
Skip Specific Policies
Integration with Husky
If you’re already using Husky, add MergeGuide to your hooks:Integration with lint-staged
Use with lint-staged for faster checks:Integration with pre-commit Framework
For the pre-commit framework, add to.pre-commit-config.yaml:
Team Setup
Automatic Installation
Add topackage.json for automatic setup:
Shared Configuration
Commit.mergeguide.yaml to your repository so all team members use the same settings.
Troubleshooting
Hook Not Running
Verify hook is installed:Hook Takes Too Long
Optimize with caching:Conflicts with Other Hooks
MergeGuide hooks are designed to work alongside other hooks. If conflicts occur:- Use a hook manager (Husky, pre-commit framework)
- Chain hooks manually in a single script