Skip to content
Tutorials Center
My learning

Topics

Git Reference ยท Configuration Options

core.hooksPath setting

Reference for core.hooksPath: point Git at a hooks directory outside .git so a team can version, share and install the same hooks in every clone.

Git looks for hook scripts in .git/hooks. That folder is not part of the repository, so hooks written there never reach teammates. core.hooksPath redirects Git to a different directory, typically one inside the working tree such as .githooks, which you can commit like any other folder.

The setting replaces the default location completely: once it is set, scripts in .git/hooks are no longer run. It can be relative or absolute and can also be set globally, which gives every repository on your machine the same hooks.

Terminal
git config core.hooksPath .githooks         # per clone: versioned folder in the repository
git config --global core.hooksPath ~/.git-hooks   # all repositories

Try it

Bash A versioned hooks folder

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.

Bash The default folder is ignored

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.

Syntax

Terminal
git config [--global] core.hooksPath <directory>
Name Description
<directory> Where Git looks for executable hook files named after the hook (pre-commit, commit-msg, ...). A relative path is resolved from the directory where the hook runs: the top of the working tree for most hooks, the Git directory for server-side ones in a bare repository. A leading ~/ expands to the home directory.

Edge cases: the hook files must be executable (chmod +x); a non-executable file is skipped with a hint. A missing folder simply means no hooks run.

Usage notes

  • Commit the folder, not the config. The setting itself lives in .git/config, which is not shared, so each clone needs one git config core.hooksPath .githooks. Put it in a setup script, make install or a package's prepare step.
  • Global use is powerful and risky. A global path also applies to repositories you clone from others, where it overrides their hooks and can run your scripts on their code. Check what your hooks assume.
  • It replaces, not adds. Hooks created by other tools in .git/hooks (Git LFS, pre-commit framework) stop firing, so copy or call them from your folder.
  • Hooks are not security. Users can skip pre-commit and commit-msg with --no-verify, and can unset the path; enforce rules again on the server or in CI.
  • Cloning does not install hooks by design, so that cloning a repository never runs code you did not review.
  • Multiple hooks per event are possible by making the file a dispatcher that runs a pre-commit.d folder, or through the hook.* config in newer Git.
  • Use git rev-parse --git-path hooks to print the folder Git currently uses.