Git Hooks Integration Guide
Automatically check commits and messages for emojis
Quick Setup with Lefthook
Lefthook is a fast, cross-platform Git hooks manager. Recommended for team projects.
1. Install Lefthook
npm install --save-dev lefthook2. Download configuration
curl https://nomoji.dev/examples/lefthook.yml -o lefthook.yml3. Add to package.json
{
"scripts": {
"prepare": "lefthook install"
}
}4. Install hooks
npm run prepareManual Setup (Alternative)
For projects without Node.js or for simple setup:
curl -s https://nomoji.dev/examples/scripts/setup-hooks.sh | bashThis installs hooks directly to .git/hooks/
What Gets Checked
Pre-commit Hook
Runs before each commit:
- Validates staged files are emoji-free
- Checks code, documentation, and comments
- Runs linting and type checking
Commit-msg Hook
Validates commit messages:
- Checks message for emojis
- Enforces conventional commit format
- Ensures professional standards
Usage
Hooks run automatically during normal Git workflow:
git add .
git commit -m "feat: add new feature"
# Lefthook automatically runs pre-commit hooks
git push
# Lefthook automatically runs pre-push hooksBypassing Hooks
In exceptional circumstances, you can bypass hooks:
# Skip pre-commit and commit-msg hooks
git commit --no-verify -m "emergency fix"
# Skip pre-push hooks
git push --no-verifyNot recommended - only for emergencies
Comparison: Lefthook vs Manual Hooks
Lefthook (Recommended)
Pros:
- Version controlled via lefthook.yml
- Automatic installation via npm
- Cross-platform compatibility
- Parallel execution
- Easy to share and update
- Team-friendly
Cons:
- Requires npm package
- Small learning curve
Manual Hooks
Pros:
- No additional dependencies
- Direct control
- Simple for single developer
Cons:
- Not version controlled
- Must be installed manually by each developer
- Hard to update and share
- Platform-specific scripts
Troubleshooting
Hooks Not Running?
- Verify installation:
npx lefthook version && ls -la .git/hooks/ - Reinstall hooks:
npx lefthook install
API Request Failures?
If emoji check fails due to network issues:
curl https://nomoji.dev/api/healthPerformance Issues?
Skip expensive checks in development:
LEFTHOOK_EXCLUDE=type-check git commitTeam Setup
To ensure all team members use the same hooks:
- Commit
lefthook.ymlto version control - Add
preparescript topackage.json - Document in README:
## Development Setup After cloning the repository: ```bash npm install # Automatically installs git hooks ```