Modern Git hooks management with configuration support, powered by Funish.
- 🚀 Simple and intuitive CLI
- ⚙️ Configuration-driven setup
- 📦 Automatic package manager detection
- 🔄 Easy migration from husky
- 🎯 Supports all Git hooks
- 💪 TypeScript support
- 🔒 Secure hook execution
- 🌟 Zero dependencies
# npm
$ npm install @funish/githooks
# yarn
$ yarn add @funish/githooks
# pnpm
$ pnpm add @funish/githooks# Install in default location (.githooks)
$ githooks install
# Install in custom directory
$ githooks install --path .hooks
# Install and save postinstall script
$ githooks install --script# Set up pre-commit hook
$ githooks setup pre-commit
# Set up with script
$ githooks setup pre-commit --script "npm test"$ githooks uninstall$ githooks migrateCreate a githooks.config.ts file:
import { defineGithooksConfig } from "@funish/githooks";
export default defineGithooksConfig({
// Custom hooks directory
path: ".hooks",
// Hook scripts
hooks: {
"pre-commit": "npm test",
"pre-push": "npm run build",
},
// Additional Git config
gitConfig: {
core: {
autocrlf: "input",
},
},
});import {
githooksInstall,
githooksSetup,
githooksUninstall,
githooksMigrateFromHusky,
} from "@funish/githooks";
// Install hooks
await githooksInstall(".hooks", true);
// Set up a hook
await githooksSetup("pre-commit", "npm test");
// Uninstall hooks
await githooksUninstall();
// Migrate from husky
await githooksMigrateFromHusky();All standard Git hooks are supported:
applypatch-msgpre-applypatchpost-applypatchpre-commitpre-merge-commitprepare-commit-msgcommit-msgpost-commitpre-rebasepost-checkoutpost-mergepre-push- And more
Installs Git hooks in the specified directory.
path(string): Directory to install hooks inisSaveScript(boolean | string): Whether to save installation script
Sets up a specific Git hook.
hooks(GithooksName): Name of the hook to set upscript(string): Script content for the hook
Uninstalls all Git hooks and restores original configuration.
Migrates hooks from Husky to @funish/githooks.
interface GithooksConfig {
path?: string; // Custom hooks directory
hooks?: {
// Hook scripts
[key in GithooksName]?: string;
};
gitConfig?: object; // Additional Git config
extends?: string | [string]; // Base config to extend
}Please read our Contributing Guide before submitting a Pull Request to the project.