Skip to content

mise generate git-pre-commit ​

Generate a git hook that runs a mise task

The hook runs mise run <TASK> (default pre-commit) with the staged file names in the STAGED environment variable. It prints the hook unless you pass --write, which saves it in the repository's hooks directory and makes it executable.

For hooks that git gives a message file (commit-msg, prepare-commit-msg, applypatch-msg, sendemail-validate), the task gets that file as an argument. Other hook arguments, such as a pre-push hook's remote name and URL, are not passed on.

For a full git hook manager, see hk: https://hk.jdx.dev

Arguments ​

  • [-- MISE_ARG]… — mise flags to embed in the generated hook, given after --

    These are inserted between mise and run, so the hook carries the same context you would pass on the command line. Useful when the config is not at the repository root, since git runs hooks from the top level: -- -C subdir makes the hook find it.

Flags ​

  • -t --task <TASK> — The task to run when the hook is triggered

    Default: pre-commit

  • -w --write — Write the hook to the hooks directory and make it executable

    The hooks directory is .git/hooks, or core.hooksPath when it is set. An existing hook of the same name is moved to <HOOK>.old.

  • --hook <HOOK> — Which git hook to write, such as pre-push

    Default: pre-commit

  • -h --help — Print help

Examples ​

Install the hook; each commit then runs mise run pre-commit

mise generate git-pre-commit --write --task=pre-commit

Use the config in subdir, since git runs hooks from the repository root

mise generate git-pre-commit --write -- -C subdir
MIT LicenseCopyright © 2026jdx.dev