Commands

Tip: Use lefthook help or lefthook <command> -h/--help to discover available commands and their options

lefthook install

Creates an empty lefthook.yml if a configuration file does not exist.

Installs configured hooks to Git hooks.

Note: NPM package lefthook installs the hooks in a postinstall script automatically. For projects not using NPM package run lefthook install after cloning the repo.

Installing specific hooks

You can install only specific hooks by running lefthook install <hook-1> <hook-2> ....

lefthook uninstall

Clears Git hooks installed by lefthook.

lefthook add

Installs the given hook to Git hook.

With argument --dirs creates a directory .git/hooks/<hook name>/ if it doesn't exist. Use it before adding a script to configuration.

Example

$ lefthook add pre-push  --dirs

Describe pre-push commands in lefthook.yml:

pre-push:
  jobs:
    - script: "audit.sh"
      runner: bash

Edit the script:

$ vim .lefthook/pre-push/audit.sh
...

Run git push and lefthook will run bash audit.sh as a pre-push hook.

lefthook run

Executes the commands and scripts configured for a given hook. Installed Git hooks call lefthook run implicitly.

Example

# lefthook.yml

pre-commit:
  jobs:
    - name: lint
      run: yarn lint --fix {staged_files}

test:
  jobs:
    - name: test
      run: yarn test

Install the hook.

$ lefthook install
$ lefthook run test # will run 'yarn test'
$ git commit # will run pre-commit hook ('yarn lint --fix')
$ lefthook run pre-commit # will run pre-commit hook (`yarn lint --fix`)

Run specific jobs

You can specify which jobs to run (also --commands and --scripts supported).

$ lefthook run pre-commit --jobs lint

Specify files

You can force replacing files templates (like {staged_files}) with either all files (will acts as {all_files} template) or a list of files.

$ lefthook run pre-commit --all-files
$ lefthook run pre-commit --file file1.js --file file2.js

(if both are specified, --all-files is ignored)

lefthook version

lefthook version prints the current binary version. Print the commit hash with lefthook version --full

Example

$ lefthook version --full

1.1.3 bb099d13c24114d2859815d9d23671a32932ffe2

lefthook self-update

Updates the binary with the latest lefthook release on Github.

This command is available only if you install lefthook from sources or download the binary from the Github Releases. For other ways use package-specific commands to update lefthook.

lefthook validate

Validates your lefthook configuration. Use lefthook dump to see it.

It uses JSON schema from the lefthook Github repo.

lefthook dump

Prints the whole configuration after merging all secondary configs.

This is the actual config lefthook uses, it can be build from the main config (lefthook.yml), remotes, extends, and lefthook-local.yml overrides.