Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

If we change `git config core.hooksPath`, how to revert back to default

By default, it looks like this is empty when run in a git repo root:

git config core.hooksPath

If we change git config core.hooksPath to git config core.hooksPath myhooks, my question is - how do we change it back to the default? Should we unset the value (how?), or should we set it to .git/hooks as in git config core.hooksPath .git/hooks?

like image 215
Alexander Mills Avatar asked May 09 '19 23:05

Alexander Mills


People also ask

How do I get rid of core hooksPath?

If the option is set in your local repository and you want to undo it, then git config --unset core. hooksPath is sufficient to unset it, which will make Git pick the default option.

What is core hooksPath?

The core. hooksPath config allows you to set a directory where the hooks are located for a repository. This is particularly useful if trying to commit your hooks to the repository (e.g. for sharing hooks with the team).

Do Git hooks get pushed?

No. Hooks are per-repository and are never pushed.


1 Answers

The answer depends on where it's set and what you want to change. If the option is set in your local repository and you want to undo it, then git config --unset core.hooksPath is sufficient to unset it, which will make Git pick the default option.

If the option is set in a higher level configuration (e.g., per-user or per-system) and you don't want to remove it from that location, only override it for this repository, you can use git config core.hooksPath .git/hooks if you are in a non-bare repository or git config core.hooksPath hooks if you are in a bare repository.

From git-config(1):

The path can be either absolute or relative. A relative path is taken as relative to the directory where the hooks are run.

From githooks(5):

Before Git invokes a hook, it changes its working directory to either $GIT_DIR in a bare repository or the root of the working tree in a non-bare repository.

Hence the requirement for .git/hooks in a non-bare repository and hooks in a bare one.

like image 78
bk2204 Avatar answered Sep 17 '22 15:09

bk2204