Simple Configuration
Configure your git hooks using TypeScript, JavaScript, or JSON. Supports multiple config formats for maximum flexibility.
A zero-dependency, type-safe tool for managing git hooks in Bun projects
# Install the package
bun add -D bun-git-hooks
# Create a configuration file
cat > git-hooks.config.ts << EOL
import type { GitHooksConfig } from 'bun-git-hooks'
const config: GitHooksConfig = {
'pre-commit': 'bun run lint && bun run test',
'commit-msg': 'bun commitlint --edit $1',
'pre-push': 'bun run build',
}
export default config
EOL
# Hooks are automatically installed!
git-hooks.config.ts
(TypeScript)git-hooks.config.js
(JavaScript)git-hooks.config.cjs
(CommonJS)git-hooks.config.json
(JSON)package.json
(with gitHooks
field)SKIP_BUN_GIT_HOOKS
: Set to "1" to skip hook executionBUN_GIT_HOOKS_RC
: Path to initialization scriptSKIP_INSTALL_GIT_HOOKS
: Set to "1" to skip hook installationconst config: GitHooksConfig = {
// Lint and test before commits
'pre-commit': 'bun run lint && bun run test',
// Validate commit messages
'commit-msg': 'bun commitlint --edit $1',
// Build and test before pushing
'pre-push': 'bun run build && bun run test:e2e',
// Update dependencies after checkout
'post-checkout': 'bun install',
// Run security checks before push
'pre-push': 'bun run security:check',
// Format code before commit
'pre-commit': 'bun run format && bun run lint',
}
Create a .git-hooks.rc
file to set up environment variables or perform custom initialization:
#!/bin/bash
export NODE_ENV=development
export CUSTOM_VAR=value
# Skip hooks for a single command
SKIP_BUN_GIT_HOOKS=1 git commit -m "message"
# Skip hook installation
SKIP_INSTALL_GIT_HOOKS=1 bun install
Join our community to get help, share ideas, and contribute:
If you find this project useful, please consider:
MIT License © 2024-present Stacks.js