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 = {
  // Note: staged-lint is only available in pre-commit hook
  'pre-commit': {
    'staged-lint': {
      '*.{js,ts}': 'bunx --bun eslint . --fix --max-warnings=0'
    }
  },
  '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 (using staged-lint)
  'pre-commit': {
    'staged-lint': {
      '*.{js,ts}': 'bunx --bun eslint . --fix --max-warnings=0',
      '*.{css,scss}': 'stylelint --fix'
    }
  },
  // 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'
}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 installJoin our community to get help, share ideas, and contribute:
If you find this project useful, please consider:
MIT License © 2024-present Stacks.js