Package Exports
- bun-git-hooks
- bun-git-hooks/cli.js
- bun-git-hooks/config.d.ts
- bun-git-hooks/git-hooks.d.ts
- bun-git-hooks/index.d.ts
- bun-git-hooks/index.js
- bun-git-hooks/types.d.ts
Readme

bun-git-hooks
A Bun-optimized TypeScript library for managing Git hooks with a robust set of configuration options.
Features
- ๐ฏ Simple Configuration: Easy setup through multiple config file formats
- ๐ Automatic Installation: Hooks are installed on package installation
- ๐ก๏ธ Type Safe: Written in TypeScript with comprehensive type definitions
- ๐ง Flexible Config: Supports
.ts,.js,.mjs,.jsonconfigurations - ๐ช Robust: Handles complex Git workspace configurations
- ๐ซ Skip Option: Environment variable to skip hook installation
- ๐งน Cleanup: Optional cleanup of unused hooks
- ๐ฆ Zero Dependencies: Minimal footprint
- โก Fast: Built for Bun with performance in mind
- ๐ Verbose Mode: Detailed logging for troubleshooting
Installation
bun add -D bun-git-hooksUsage
Basic Configuration
Create a git-hooks.config.ts (or .js, .mjs, .cjs, .mts, .cts, .json) file in your project root:
export default {
'pre-commit': 'bun run lint && bun run test',
'commit-msg': 'bun commitlint --edit $1',
'pre-push': 'bun run build'
}Or add to your package.json:
{
"git-hooks": {
"pre-commit": "bun run lint && bun run test",
"commit-msg": "bun commitlint --edit $1",
"pre-push": "bun run build"
}
}CLI Usage
# Install hooks from config
git-hooks
# alternatively, trigger the CLI with bunx
bunx git-hooks
bunx bun-git-hooks
# Use specific config file
git-hooks ./custom-config.ts
# Remove all hooks
git-hooks uninstall
# Enable verbose logging
git-hooks --verboseEnvironment Variables
Skip hook installation when needed:
# Skip hook installation
SKIP_INSTALL_GIT_HOOKS=1 bun install
# Set custom environment for hooks
BUN_GIT_HOOKS_RC=/path/to/env git-hooksAdvanced Configuration
export default {
// Hook commands
'pre-commit': 'bun run lint && bun run test',
'commit-msg': 'bun commitlint --edit $1',
// Preserve specific unused hooks
'preserveUnused': ['post-merge', 'post-checkout'],
// Configure multiple hooks
'pre-push': [
'bun run build',
'bun run test:e2e'
].join(' && ')
}Error Handling
The library provides clear error messages:
try {
await setHooksFromConfig()
}
catch (err) {
if (err.message.includes('Config was not found')) {
console.error('Missing configuration file')
}
else if (err.message.includes('git root')) {
console.error('Not a Git repository')
}
}TypeScript Support
Full TypeScript support with detailed type definitions:
interface GitHooksConfig {
'pre-commit'?: string
'pre-push'?: string
'commit-msg'?: string
'post-merge'?: string
// ... other git hooks
'preserveUnused'?: Array<string> | boolean
}
// Types are automatically inferred
const config: GitHooksConfig = {
'pre-commit': 'bun run test',
'preserveUnused': ['post-checkout']
}Testing
bun testChangelog
Please see our releases page for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Community
For help, discussion about best practices, or any other conversation that would benefit from being searchable:
For casual chit-chat with others using this package:
Join the Stacks Discord Server
Postcardware
Stacks OSS will always stay open-sourced, and we will always love to receive postcards from wherever Stacks is used! And we also publish them on our website.
Our address: Stacks.js, 12665 Village Ln #2306, Playa Vista, CA 90094, United States ๐
Credits
Many thanks to simple-git-hooks and its contributors for inspiring this project.
Sponsors
We would like to extend our thanks to the following sponsors for funding Stacks development. If you are interested in becoming a sponsor, please reach out to us.
License
The MIT License (MIT). Please see LICENSE for more information.
Made with ๐