Lefthook is a fast, powerful, and dependency-free Git hooks manager that automates and controls Git hook execution across various programming environments.
Fast and powerful Git hooks manager for any type of projects.
Lefthook is used by developers and DevSecOps teams to automate and manage Git hooks efficiently, ensuring code quality and security checks run consistently before commits or pushes. It is ideal for projects in Node.js, Ruby, Python, and other languages, enabling parallel execution and flexible file filtering to optimize pre-commit, pre-push, and other Git hook workflows.
Lefthook requires Git and appropriate language runtimes (Node.js, Ruby, Python) for executing configured commands. Its single binary design ensures minimal setup complexity. Best practice includes configuring hooks carefully to avoid slowing down Git operations, leveraging parallel execution and selective file filtering to optimize performance.
Install with Go (>= 1.24): go install github.com/evilmartians/lefthook@latest
Or as a Go tool: go get -tool github.com/evilmartians/lefthook
Install with NPM: npm install lefthook --save-dev
Install with Ruby gem: gem install lefthook
Install with Python pip: pip install lefthook
Refer to installation guide for apt, brew, winget, and other methods
vim lefthook.yml
Configure your Git hooks in the lefthook.yml file
lefthook install
Install the configured Git hooks into the current Git project
git add -A && git commit -m '...'
Standard Git workflow that triggers Lefthook-managed hooks during commit
pre-push: parallel: true
Enable parallel execution of jobs in the pre-push hook
pre-commit: jobs: - name: lint frontend run: yarn eslint {staged_files}
Run ESLint on staged frontend files during pre-commit
pre-commit: jobs: - name: lint backend glob: "*.rb" exclude: '(^|/)(application|routes)\.rb$' run: bundle exec rubocop --force-exclusion {all_files}
Run RuboCop on Ruby files excluding specific patterns during pre-commit
commit-msg: jobs: - script: "template_checker" runner: bash
Run a custom bash script named template_checker during commit-msg hook