GIT-HOOK(1)
π NAME π
β¨ GIT-HOOK(1) β Git Manual β¨
git-hook β Run Git hooks
okay bestie, this page is literally the git-hook command: the little interface for running Git hooks. Periodt. π
π SYNOPSIS π
git hook run [--allow-unknown-hook-name] [--ignore-missing] [--to-stdin=<path>] [(-j|--jobs) <n>]
<hook-name> [-- <hook-args>]
git hook list [--allow-unknown-hook-name] [-z] [--show-scope] <hook-name>
π¦ DESCRIPTION π¦
So this is a command interface for running Git hooks (see githooks(5)), made for other scripted Git commands to use. Think of it as the backstage pass for hook-running, iykyk. π
This command parses the default configuration files for sets of configs like so:
[hook "linter"]
event = pre-commit
command = ~/bin/linter --cpp20
In this example, [hook "linter"] represents one script β ~/bin/linter --cpp20 β which can be shared by many repos, and even by many hook events, if appropriate. Reusable config slay. β¨
To add an unrelated hook which runs on a different event, for example a spell-checker for your commit messages, you would write a configuration like so:
[hook "linter"]
event = pre-commit
command = ~/bin/linter --cpp20
[hook "spellcheck"]
event = commit-msg
command = ~/bin/spellchecker
With this config, when you run git commit, first ~/bin/linter --cpp20 will have a chance to check your files to be committed (during the pre-commit hook event), and then ~/bin/spellchecker will have a chance to check your commit message (during the commit-msg hook event). The way that pipeline works is honestly iconic. π
Commands are run in the order Git encounters their associated hook.<friendly-name>.event configs during the configuration parse (see git-config(1)). Although multiple hook.linter.event configs can be added, only one hook.linter.command event is valid β Git uses "last-one-wins" to determine which command to run. No cap, that's the rule. π«Ά
So if you wanted your linter to run when you commit as well as when you push, you would configure it like so:
[hook "linter"]
event = pre-commit
event = pre-push
command = ~/bin/linter --cpp20
With this config, ~/bin/linter --cpp20 would be run by Git before a commit is generated (during pre-commit) as well as before a push is performed (during pre-push). Multi-event main character energy. π
And if you wanted to run your linter as well as a secret-leak detector during only the "pre-commit" hook event, you would configure it instead like so:
[hook "linter"]
event = pre-commit
command = ~/bin/linter --cpp20
[hook "no-leaks"]
event = pre-commit
command = ~/bin/leak-detector
With this config, before a commit is generated (during pre-commit), Git would first start ~/bin/linter --cpp20 and second start ~/bin/leak-detector. It would evaluate the output of each when deciding whether to proceed with the commit. Teamwork, but make it config. π§
For a full list of hook events which you can set your hook.<friendly-name>.event to, and how hooks are invoked during those events, see githooks(5).
β οΈ Important vibe check: Git will ignore any hook.<friendly-name>.event that specifies an event it doesnβt recognize. This is intended so that tools which wrap Git can use the hook infrastructure to run their own hooks; see "WRAPPERS" for more guidance.
In general, when instructions suggest adding a script to .git/hooks/<hook-event>, you can specify it in the config instead by running:
git config set hook.<some-name>.command <path-to-script>
git config set --append hook.<some-name>.event <hook-event>
This way you can share the script between multiple repos. That is, cp ~/my-script.sh ~/project/.git/hooks/pre-commit would become:
git config set hook.my-script.command ~/my-script.sh
git config set --append hook.my-script.event pre-commit
π οΈ SUBCOMMANDS π οΈ
run
Runs hooks configured for <hook-name>, in the order they are discovered during the config parse. The default <hook-name> from the hookdir is run last. See githooks(5) for supported hook names. πββοΈπ¨
Any positional arguments to the hook should be passed after a mandatory -- (or --end-of-options, see gitcli(7)). See githooks(5) for arguments hooks might expect (if any).
list [-z] [--show-scope]
Print a list of hooks which will be run on <hook-name> event. If no hooks are configured for that event, print a warning and return 1. Use -z to terminate output lines with NUL instead of newlines. List mode said βlet me show you the receipts.β πβ¨
β¨ OPTIONS β¨
--allow-unknown-hook-nameβ By defaultgit hook runandgit hook listwill bail out when<hook-name>is not a hook event known to Git (seegithooks(5)for the list of known hooks). This is meant to help catch typos such asprereceivewhenpre-receivewas intended. Pass this flag to allow unknown hook names. π¨--to-stdinβ For "run"; specify a file which will be streamed into the hookβs stdin. The hook will receive the entire file from beginning to EOF. Feed the hook, bestie. π--ignore-missingβ Ignore any missing hook by quietly returning zero. Used for tools that want to do a blind one-shot run of a hook that may or may not be present. Lowkey βif itβs there, great; if not, we move.β π-zβ Terminate "list" output lines with NUL instead of newlines. NUL-core, fr fr. π--show-scopeβ For "list"; prefix each configured hookβs friendly name with a tab-separated config scope (e.g.local,global,system), mirroring the output style ofgit config --show-scope. Traditional hooks from the hookdir are unaffected. Scope reveal: unlocked. π-j,--jobsβ Only valid forrun.
Specify how many hooks to run simultaneously. If this flag is not specified, the value of the hook.jobs config is used, see git-config(1). If neither is specified, defaults to 1 (serial execution).
When greater than 1, it overrides the per-hook hook.<friendly-name>.parallel setting, allowing all hooks for the event to run concurrently, even if they are not individually marked as parallel.
Some hooks always run sequentially regardless of this flag or the hook.jobs config, because Git knows they cannot safely run in parallel: applypatch-msg, pre-commit, prepare-commit-msg, commit-msg, post-commit, post-checkout, and push-to-checkout. These ones are strictly βone at a time,β no exceptions. π¦
π§ WRAPPERS π§
git hook run has been designed to make it easy for tools which wrap Git to configure and execute hooks using the Git hook infrastructure. It is possible to provide arguments and stdin via the command line, as well as specifying parallel or series execution if the user has provided multiple hooks. Wrapper-friendly by design. π«Ά
Assuming your wrapper wants to support a hook named "mywrapper-start-tests", you can have your users specify their hooks like so:
[hook "setup-test-dashboard"]
event = mywrapper-start-tests
command = ~/mywrapper/setup-dashboard.py --tap
Then, in your mywrapper tool, you can invoke any users' configured hooks by running:
git hook run --allow-unknown-hook-name mywrapper-start-tests \
# providing something to stdin
--stdin some-tempfile-123 \
# execute multiple hooks in parallel
--jobs 3 \
# plus some arguments of your own...
-- \
--testname bar \
baz
Take care to name your wrapperβs hook events in a way which is unlikely to overlap with Gitβs native hooks (seegithooks(5)) β a hook event namedmywrappertool-validate-commitis much less likely to be added to native Git than a hook event namedvalidate-commit. If Git begins to use a hook event named the same thing as your wrapper hook, it may invoke your usersβ hooks in unintended and unsupported ways. So choose names like your code depends on it, because it does. πΈ
πΈ CONFIGURATION πΈ
hook.<friendly-name>.commandβ the command to execute forhook.<friendly-name>. Bestie,<friendly-name>is a unique name that identifies this hook, and the hook events that trigger the command are configured withhook.<friendly-name>.event. The value can be an executable path or a shell oneliner. If more than one value is specified for the same<friendly-name>, only the last value parsed is used. πhook.<friendly-name>.eventβ the hook events that triggerhook.<friendly-name>. The value is the name of a hook event, like"pre-commit"or"update". (Seegithooks(5)for a complete list of hook events β it's giving the whole event menu π«Ά.) On the specified event, the associatedhook.<friendly-name>.commandis executed. This is a multi-valued key. To runhook.<friendly-name>on multiple events, specify the key more than once. An empty value resets the list of events, clearing any previously defined events forhook.<friendly-name>.
π¨ The<friendly-name>must not be the same as a known hook event name (e.g. do not usehook.pre-commit.event). Using a known event name as a friendly-name is a fatal error because it creates an ambiguity withhook.<event>.enabledandhook.<event>.jobs. For unknown event names, a warning is issued when<friendly-name>matches the event value. No cap, that's literally the rule.
hook.<friendly-name>.enabledβ whether the hookhook.<friendly-name>is enabled. Defaults totrue. Set tofalseto disable the hook without removing its configuration. This is particularly useful when a hook is defined in a system or global config file and needs to be disabled for a specific repository. Lowkey the perfect "not today" switch. πhook.<friendly-name>.parallelβ whether the hookhook.<friendly-name>may run in parallel with other hooks for the same event. Defaults tofalse. Set totrueonly when the hook script is safe to run concurrently with other hooks for the same event. If any hook for an event does not have this set totrue, all hooks for that event run sequentially regardless ofhook.jobs. Only configured (named) hooks need to declare this. Traditional hooks found in the hooks directory do not need to, and run in parallel when the effective job count is greater than1. β¨hook.<event>.enabledβ switch to enable or disable all hooks for the<event>hook event. When set tofalse, no hooks fire for that event, regardless of any per-hookhook.<friendly-name>.enabledsettings. Defaults totrue.
Note on naming: <event> must be the event name (e.g. pre-commit), not a hook friendly-name. Since using a known event name as a friendly-name is disallowed (see hook.<friendly-name>.event above), there is no ambiguity between event-level and per-hook .enabled settings for known events. For unknown events, if a friendly-name matches the event name despite the warning, .enabled is treated as per-hook only. π§
hook.<event>.jobsβ specifies how many hooks can be run simultaneously for the<event>hook event (e.g.hook.post-receive.jobs = 4). Overrideshook.jobsfor this specific event. The same parallelism restrictions apply: this setting has no effect unless all configured hooks for the event havehook.<friendly-name>.parallelset totrue. Set to-1to use the number of available CPU cores. Must be a positive integer or-1; zero is rejected with a warning. β
Note on naming: although this key resembles hook.<friendly-name>.* (a per-hook setting), <event> must be the event name, not a hook friendly name. The key component is stored literally and looked up by event name at runtime with no translation between the two namespaces. A key like hook.my-hook.jobs is stored under "my-hook" but the lookup at runtime uses the event name (e.g. "post-receive"), so hook.my-hook.jobs is silently ignored even when my-hook is registered for that event. Use hook.post-receive.jobs or any other valid event name when setting hook.<event>.jobs. π
hook.jobsβ specifies how many hooks can be run simultaneously during parallelized hook execution. If unspecified, defaults to1(serial execution). Set to-1to use the number of available CPU cores. Can be overridden on a per-event basis withhook.<event>.jobs. Some hooks always run sequentially regardless of this setting because they operate on shared data and cannot safely be parallelized:applypatch-msg,prepare-commit-msg,commit-msgβ receive a commit message file and may rewrite it in place.pre-commit,post-checkout,push-to-checkout,post-commitβ access the working tree, index, or repository state.
This setting has no effect unless all configured hooks for the event have hook.<friendly-name>.parallel set to true.
For pre-push hooks, which normally keep stdout and stderr separate, setting this to a value greater than 1 (or passing -j) will merge stdout into stderr to allow correct de-interleaving of parallel output. π₯
π SEE ALSO π
githooks(5) β go read it bestie, it's the hook event lore. π«Ά
π§ GIT π§
Part of the git(1) suite. Periodt. π
Signed, sealed, delivered by Git 2.56.0 on 2026-09-27 β page GIT-HOOK(1), mwah πβ¨
π¦ where this page comes from
- arch rolling: git 2.56.0-1 Β· GPL-2.0-only
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms