Skip to content

bun-git-hooksModern Git Hooks Management

A zero-dependency, type-safe tool for managing git hooks in Bun projects

bun-git-hooks logo

Quick Start

bash
# 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!

Why bun-git-hooks?

  • 🎯 Simple Yet Powerful: Easy to set up, but packed with features
  • 🔄 Team Friendly: Automatically install hooks for all team members
  • 🛡️ Type Safe: Full TypeScript support with great IDE integration
  • 📦 Zero Dependencies: Minimal footprint in your project
  • Fast: Built for Bun with performance in mind
  • 🔧 Flexible: Multiple configuration formats and options

Configuration Options

Supported Config Files

  • 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)

Environment Variables

  • SKIP_BUN_GIT_HOOKS: Set to "1" to skip hook execution
  • BUN_GIT_HOOKS_RC: Path to initialization script
  • SKIP_INSTALL_GIT_HOOKS: Set to "1" to skip hook installation
ts
const 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',
}

Advanced Features

Custom Initialization Scripts

Create a .git-hooks.rc file to set up environment variables or perform custom initialization:

bash
#!/bin/bash
export NODE_ENV=development
export CUSTOM_VAR=value

Skip Hooks Temporarily

bash
# 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

Community

Join our community to get help, share ideas, and contribute:

Support

If you find this project useful, please consider:

License

MIT License © 2024-present Stacks.js

Meet The Team

Chris Breuer's avatar
Chris Breuer
Open sourceror.
Core Stacks team.
Working at Stacks.js
Glenn's avatar
Glenn
Open sourceror.
Core Stacks team.
Working at Stacks.js
Mike's avatar
Mike
Open sourceror.
Core Stacks team.
Working at Stacks.js
Zoltan's avatar
Zoltan
Open sourceror.
Core Stacks team.

Stacks Sponsors

Click here to become a sponsor.

Contributors

chrisbbreuer's avatarcab-mikee's avatar

Released under the MIT License.