Lefthook provides a comprehensive command-line interface for managing Git hooks across different development environments.
Install Git hooks in the current repository.
lefthook install [flags]
# Flags:
--force, -f # Overwrite .old hooks (deprecated, no longer needed)Usage Example:
# Install hooks in repository
lefthook install
# Install with verbose output
lefthook install --verboseRemove Git hooks from the current repository.
lefthook uninstall [flags]
# Flags:
--force, -f # Remove all git hooks even not lefthook-related
--remove-configs, -c # Remove lefthook main and secondary config filesUsage Example:
# Remove all lefthook hooks
lefthook uninstallVerify the installation status of Git hooks.
lefthook check_install [flags]
# No additional flags beyond global optionsUsage Example:
# Check if hooks are properly installed
lefthook check_installExecute specific hooks or hook commands.
lefthook run <hook_name> [git_args...] [flags]
# Arguments:
# hook_name Required. Git hook name (pre-commit, pre-push, etc.)
# git_args Optional. Git hook arguments passed by Git itself
# Flags:
--force, -f # Force execution of commands that can be skipped
--all-files # Run on all files instead of changed files
--no-tty, -n # Run hook non-interactively, disable spinner
--no-auto-install # Skip updating git hooks
--skip-lfs # Skip running git lfs
--files-from-stdin # Get files from standard input, null-separated
--file strings # Run on specified file (repeat for multiple files)
--exclude strings # Exclude specified file (repeat for multiple files)
--commands strings # Run only specified commands
--jobs strings # Run only specified jobsAvailable Hook Names:
applypatch-msgpre-applypatchpost-applypatchpre-commitpre-merge-commitprepare-commit-msgcommit-msgpost-commitpre-rebasepost-checkoutpost-mergepre-pushpre-receiveupdateproc-receivepost-receivepost-updatereference-transactionpush-to-checkoutpre-auto-gcpost-rewritesendemail-validatefsmonitor-watchmanp4-changelistp4-prepare-changelistp4-post-changelistp4-pre-submitpost-index-changeUsage Examples:
# Run all pre-commit hooks
lefthook run pre-commit
# Run specific commands in pre-commit hook
lefthook run pre-commit --commands lint,test
# Run specific jobs in pre-commit hook
lefthook run pre-commit --jobs build,deploy
# Run on all files
lefthook run pre-commit --all-files
# Force execution
lefthook run pre-commit --force
# Run with custom files
lefthook run pre-commit --file src/app.js --file src/utils.jsAdd new hook configuration to the lefthook configuration file.
lefthook add <hook_name> [flags]
# Arguments:
# hook_name Required. Git hook name to add
# Flags:
--dirs, -d # Create directory for scripts
--force, -f # Overwrite .old hooksUsage Example:
# Add pre-commit hook configuration
lefthook add pre-commit
# Add pre-push hook configuration
lefthook add pre-pushValidate the lefthook configuration file syntax and structure.
lefthook validate [flags]
# No additional flags beyond global optionsUsage Example:
# Validate configuration
lefthook validate
# Validate with verbose output
lefthook validate --verboseExport the current configuration to stdout.
lefthook dump [flags]
# Flags:
--format, -f # Output format: 'yaml', 'toml', or 'json'
--json, -j # Dump in JSON format (deprecated)
--toml, -t # Dump in TOML format (deprecated)Usage Example:
# Export configuration
lefthook dump
# Export and save to file
lefthook dump > exported-config.ymlDisplay version information.
lefthook version [flags]
# Flags:
--full, -f # Full version with commit hashUsage Example:
# Show version
lefthook versionUpdate lefthook binary to the latest version.
lefthook self-update [flags]
# Flags:
--yes, -y # No prompt
--force, -f # Force upgrade
--verbose, -v # Show verbose logsUsage Example:
# Update to latest version
lefthook self-updateAll commands support these global flags:
--verbose, -v # Enable verbose output
--colors string # Color output: 'auto', 'on', or 'off' (default: 'auto')
--no-colors # Disable colored output (deprecated, use --colors=off)Lefthook supports shell auto-completion for commands and hook names. The completion system provides:
run and add commandsEach command returns appropriate exit codes:
0: Success1: Error occurredCommands provide detailed error messages and support verbose output for troubleshooting configuration and execution issues.