Skip to content

Git hooks

Use git hooks to automatically run oneRepo tasks and other commands before, during, and after git commands using git hooks.

Git hooks can be a divisive topic. Because of that, managing the hooks through oneRepo is an opt-in behavior with multiple options.

Set vcs.autoSyncHooks: true in your root config. This will ensure git is configured to use your hooks after any successful command run.

export default {
vcs: {
autoSyncHooks: true,

If you and your team do not want to always require git hooks to be configured in dev environments, any individual developer can run the commands to initialize and create hooks at will:

Set up initial hooks configuration
one hooks init

Then you may create hooks either by using the oneRepo recommended hooks or add & edit them manually:

Create recommended hooks
one hooks create
Create a custom hook
one hooks create --hook prepare-commit-msg

All hooks will be created within the vcs.hooksPath config (./.hooks by default) unless otherwise modified. Once created, make sure the to commit the hook files to git so they can be shared.

You can bypass pre-commit and commit-msg hooks using Git --no-verify/-n option:

Terminal window
git commit --no-verify

For Git commands that don’t have a --no-verify option, you can set the ONEREPO_USE_HOOKS environment variable to "0" and hooks will exit before executing any configured tasks:

Terminal window
ONEREPO_USE_HOOKS="0" git pull

For one-off uses or as an individual setting not tracked in your config, set an environment variable ONEREPO_SYNC_HOOKS to 0. This will prevent the background task that automatically updates git with knowledge of the hooks:

Terminal window

To uninstall the git hooks, unset the local git config value. Ensure you also disable auto-sync by setting vcs.autoSyncHooks to false.

Terminal window
git config --unset core.hooksPath

Manage git repository hooks

Terminal window
one hooks <command>

Create git hooks

Terminal window
one hooks create
--addboolean, default: trueAdd the hooks to the git stage for committing.
--hook"applypatch-msg", "pre-applypatch", "post-applypatch", "pre-commit", "pre-merge-commit", "prepare-commit-msg", "commit-msg", "post-commit", "pre-rebase", "post-checkout", "post-merge", "pre-receive", "update", "post-receive", "post-update", "pre-auto-gc", "post-rewrite", "pre-push", "proc-receive", "push-to-checkout", default: ["pre-commit","post-checkout","post-merge","post-rewrite"]The git hook to create. Omit this option to auto-create recommended hooks.
--overwritebooleanOverwrite existing hooks
Advanced options
--hooks-pathstringTracked path to use for git hooks. This option is defaulted via the oneRepo root config.

Aliases: one hooks sync

Initialize and sync git hook settings for this repository.

Terminal window
one hooks init
Advanced options
--hooks-pathstringTracked path to use for git hooks.

Many of the ideas and code patterns for this module were inspired by Husky, which has been a long time standard utility for JavaScript based repos.