用 Go 安装需 Go >= 1.27;安装后必须执行 lefthook install 才会写入 git hooks;root 路径需带结尾斜杠
lefthook
evilmartiansMIT活跃维护用 Go 写的 Git hooks 管理器,能并行执行 pre-commit、pre-push 等钩子,配置简单、速度快,适合各种语言的项目统一管理提交前检查。
Fast and powerful Git hooks manager for any type of projects.
npm install lefthook --save-dev
lefthook installREADME 未说明,仅需能运行 Go 编译的二进制或对应包管理器的环境,无 GPU 要求
用 Go 写的 Git hooks 管理器,跨语言项目都能用,配置一次即可并行跑检查
用 Go 写的 Git hooks 管理器,能并行执行 pre-commit、pre-push 等钩子,配置简单、速度快,适合各种语言的项目统一管理提交前检查。
核心能力
- 用 Go 编写的单文件无依赖二进制,任意环境可用
- 支持 parallel 并行执行多个 hook 命令
- 用 {staged_files}、{all_files} 等占位符灵活传入文件列表
- 支持 glob 与 exclude 正则过滤文件
- 用 tags 和 lefthook-local.yml 按人按需跳过或覆盖命令
容易踩的坑
- v2.2.2最新正式版2026-10-13 · 2026-10-13 09:20 UTC
Changelog
- 4aeffd72a6e3ea846c2054cffd6294c943fd7fbb fix: cleanup only current stash hash (#1597)
- db62412c82ddac71cf536e60e50edb2826624870 packaging: add support for android (#1591)
- e3fa81b1f01881829ef95e37211da7923a4fd6df refactor(filter): simplify mimetype matching (#1596)
- v2.2.12026-10-08 · 2026-10-08 10:35 UTC
查看更新说明
Changelog
- 6dd11f61f54595935746f9e0814c16844fc6d31b feat: support php composer (#1583)
- c702ccf154bb180107ba5f790518c161d9ce111d fix: generate different patch names when in a worktree (#1582)
- 486fdd317d29f815821ce2450d42e3a49b066eb0 refactor: cache paths in wrapper (#1570)
- v2.2.02026-10-07 · 2026-10-07 19:08 UTC
查看更新说明
Changelog
- 46c65b3871dd96c81624f413b24b3d273b41a4e5 deps: October 2026 (#1571)
- 37f17131b605cf0f64c29252ebfe94610368f769 fix: don't write an install-time lefthook path into AI hook configs (#1544)
- cc9969c2e2198aafff8accc63ee1aee30e9a2aa4 fix: ignore trailing NUL in --files-from-stdin (#1574)
- 57fee374b70c18e17ada20e09a336142d6d8899f fix: pass --output path to git diff as a single argument (#1581)
- v2.1.172026-10-05 · 2026-10-05 07:47 UTC
查看更新说明
Changelog
- 8d8073d427fac49cc982919f5280b295645d196d fix: diff push files against the merge base with the default branch (#1565)
- c12bccd193f43a8419038787bd83b12fe3a4470c fix: don't hash submodules when checking fail_on_changes (#1566)
- 03225efde40226b14459e901707fbd988d62fcc0 refactor: naming of helpers (#1568)
- 66746ace996c72ac31b3cb4a70af85607568baf4 refactor: working with git (#1564)
- v2.1.162026-10-01 · 2026-10-01 17:29 UTC
查看更新说明
Changelog
- 3ee04318fd06d56a70cc9c90dc8385b19918f520 ci: refactor publishing scripts (#1559)
- 91407e537b2fa36539506963a33e582dca394798 deps: bump mod and text deps to resolve CVEs (#1560)
- be6f0ae8793533449cb9a07a253fa9a381e82206 fix: preserve unrelated unstaged changes on conflict (#1483)
- cf4ef1e19baf0581871f69b40914d64c94ff19d7 fix: test staging fixed files with partially staged
用户点评
登录用户的真实使用记录,可按版本和硬件筛选还没有人点评。第一个说出真实体验的人最有价值。
Lefthook
A Git hooks manager for Node.js, Ruby, Python and many other types of projects.
- Fast. It is written in Go. Can run commands in parallel.
- Powerful. It allows to control execution and files you pass to your commands.
- Simple. It is single dependency-free binary which can work in any environment.
Lefthook is built by Evil Martians, an American design and engineering consultancy for developer tools, AI, and cybersecurity startups.
Install
With Go (>= 1.27):
go install github.com/evilmartians/lefthook/[email protected]
- or as a go tool
go get -tool github.com/evilmartians/lefthook/[email protected]
With NPM:
npm install lefthook --save-dev
For Ruby:
gem install lefthook
For Python:
pipx install lefthook
Installation guide with more ways to install lefthook: apt, brew, winget, and others.
Usage
Configure your hooks, install them once and forget about it: rely on the magic underneath.
TL;DR
# Configure your hooks
vim lefthook.yml
# Install them to the git project
lefthook install
# Enjoy your work with git
git add -A && git commit -m '...'
More details
- Configuration for
lefthook.ymlconfig options. - Usage for lefthook CLI options, and features.
- Discussions for questions, ideas, suggestions.
Why Lefthook
-
Parallel execution
Gives you more speed. docs
pre-push:
parallel: true
-
Flexible list of files
If you want your own list. Custom and prebuilt examples.
pre-commit:
jobs:
- name: lint frontend
run: yarn eslint {staged_files}
- name: lint backend
run: bundle exec rubocop --force-exclusion -- {all_files}
- name: stylelint frontend
files: git diff --name-only HEAD @{push}
run: yarn stylelint {files}
-
Glob and regexp filters
If you want to filter list of files. You could find more glob pattern examples here.
pre-commit:
jobs:
- name: lint backend
glob: "*.rb" # glob filter
exclude:
- "*/application.rb"
- "*/routes.rb"
run: bundle exec rubocop --force-exclusion -- {all_files}
-
Execute in sub-directory
If you want to execute the commands in a relative path
pre-commit:
jobs:
- name: lint backend
root: "api/" # Careful to have only trailing slash
glob: "*.rb" # glob filter
run: bundle exec rubocop -- {all_files}
-
Run scripts
If oneline commands are not enough, you can execute files. docs
commit-msg:
jobs:
- script: "template_checker"
runner: bash
-
Tags
If you want to control a group of commands. docs
pre-push:
jobs:
- name: audit packages
tags:
- frontend
- linters
run: yarn lint
- name: audit gems
tags:
- backend
- security
run: bundle audit
-
Support Docker
If you are in the Docker environment. docs
pre-commit:
jobs:
- script: "good_job.js"
runner: docker run -it --rm <container_id_or_name> {cmd}
-
Local config
If you are a frontend/backend developer and want to skip unnecessary commands or override something in Docker. docs
# lefthook-local.yml
pre-push:
exclude_tags:
- frontend
jobs:
- name: audit packages
skip: true
-
Direct control
If you want to run hooks group directly.
$ lefthook run pre-commit
-
Your own tasks
If you want to run specific group of commands directly.
fixer:
jobs:
- run: bundle exec rubocop --force-exclusion --safe-auto-correct -- {staged_files}
- run: yarn eslint --fix {staged_files}
$ lefthook run fixer
-
Control output
You can control what lefthook prints with output option.
output:
- execution
- failure
Guides
- Install with Node.js
- Install with Ruby
- Install with Homebrew
- Install with Winget
- Install for Debian-based Linux
- Install for RPM-based Linux
- Install for Arch Linux
- Install for Alpine Linux
- Usage
- Configuration
Examples
Check examples
Articles
- 5 cool (and surprising) ways to configure Lefthook for automation joy
- Lefthook: Knock your team’s code back into shape
- Lefthook + Crystalball
- Keeping OSS documentation in check with docsify, Lefthook, and friends
- Automatically linting docker containers
- Smooth PostgreSQL upgrades in DockerDev environments with Lefthook
- Lefthook for React/React Native apps