Installation
Installing bun-git-hooks
is straightforward. You can install it using your preferred package manager or download the binary directly.
Package Managers
Choose your package manager of choice:
sh
bun add -D bun-git-hooks
sh
npm install --save-dev bun-git-hooks
sh
pnpm add -D bun-git-hooks
sh
yarn add -D bun-git-hooks
Binary Installation
You can also install bun-git-hooks
as a binary. Choose the binary that matches your platform and architecture:
sh
# Download the binary
curl -L https://github.com/stacksjs/bun-git-hooks/releases/latest/download/bun-git-hooks-darwin-arm64 -o bun-git-hooks
# Make it executable
chmod +x bun-git-hooks
# Move it to your PATH
mv bun-git-hooks /usr/local/bin/bun-git-hooks
sh
# Download the binary
curl -L https://github.com/stacksjs/bun-git-hooks/releases/latest/download/bun-git-hooks-darwin-x64 -o bun-git-hooks
# Make it executable
chmod +x bun-git-hooks
# Move it to your PATH
mv bun-git-hooks /usr/local/bin/bun-git-hooks
sh
# Download the binary
curl -L https://github.com/stacksjs/bun-git-hooks/releases/latest/download/bun-git-hooks-linux-arm64 -o bun-git-hooks
# Make it executable
chmod +x bun-git-hooks
# Move it to your PATH
mv bun-git-hooks /usr/local/bin/bun-git-hooks
sh
# Download the binary
curl -L https://github.com/stacksjs/bun-git-hooks/releases/latest/download/bun-git-hooks-linux-x64 -o bun-git-hooks
# Make it executable
chmod +x bun-git-hooks
# Move it to your PATH
mv bun-git-hooks /usr/local/bin/bun-git-hooks
sh
# Download the binary
curl -L https://github.com/stacksjs/bun-git-hooks/releases/latest/download/bun-git-hooks-windows-x64.exe -o bun-git-hooks.exe
# Move it to your PATH (adjust the path as needed)
move bun-git-hooks.exe C:\Windows\System32\bun-git-hooks.exe
TIP
You can also find the bun-git-hooks
binaries in GitHub releases.
Configuration
After installation, you'll need to create a configuration file. The package supports multiple configuration formats:
ts
// git-hooks.config.ts
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
js
// git-hooks.config.js
module.exports = {
'pre-commit': 'bun run lint && bun run test',
'commit-msg': 'bun commitlint --edit $1',
'pre-push': 'bun run build',
}
json
// git-hooks.config.json
{
"pre-commit": "bun run lint && bun run test",
"commit-msg": "bun commitlint --edit $1",
"pre-push": "bun run build"
}
json
{
"gitHooks": {
"pre-commit": "bun run lint && bun run test",
"commit-msg": "bun commitlint --edit $1",
"pre-push": "bun run build"
}
}
Post-Installation
After installation and configuration:
- The hooks will be automatically installed when you run
bun install
- You can verify the installation by checking the
.git/hooks
directory - To test if hooks are working, try making a commit
Environment Variables
You can control the behavior of bun-git-hooks
using environment variables:
bash
# Skip hook execution
SKIP_BUN_GIT_HOOKS=1 git commit -m "message"
# Skip hook installation
SKIP_INSTALL_GIT_HOOKS=1 bun install
# Use custom initialization script
BUN_GIT_HOOKS_RC=./.git-hooks.rc
Troubleshooting
If you encounter any issues during installation:
- Ensure you have the latest version of Bun installed
- Check that your configuration file is valid
- Verify that
bun-git-hooks
is in yourdevDependencies
- Try running with verbose mode enabled in your config