I have a git installed in "Programm files" directory and I have not modified rights to it (only reading). But i want to put some new hooks. Is there a way to call git in command line and specify new path for hooks directory?
1 Answers
Git hooks are local to a repo.
Once you have created a repo (git init yourRepo
), you will see those hooks in yourRepo/.git/hooks
.
Update May 2016 for git 2.9 (June 2016)
You have a new config: core.hooksPath
See commit 867ad08, commit de0824e, commit bf7d977, commit 49fa52f (04 May 2016) by Ævar Arnfjörð Bjarmason (avar
).
(Merged by Junio C Hamano -- gitster
-- in commit 6675f50, 17 May 2016)
core.hooksPath
By default Git will look for your hooks in the '
$GIT_DIR/hooks
' directory.
Set this to different path, e.g. '/etc/git/hooks
', and Git will try to find your hooks in that directory, e.g. '/etc/git/hooks/pre-receive
' instead of in '$GIT_DIR/hooks/pre-receive
'.The path can be either absolute or relative. A relative path is taken as relative to the directory where the hooks are run
The "relative path" part comes from the Git Hooks man page:
Before Git invokes a hook, it changes its working directory to either the root of the working tree in a non-bare repository, or to the
$GIT_DIR
in a bare repository.
Original answer (Feb. 2014)
You could specify a different templatedir (from git config
)
init.templatedir
Specify the directory from which templates will be copied. (See the "TEMPLATE DIRECTORY" section of
git-init
(1).)The default template directory includes some directory structure, some suggested "exclude patterns", and copies of sample "hook" files.
The suggested patterns and hook files are all modifiable and extensible.
That would means a new repo (git init
) would fill the default content (including default sample hooks) from a custom folder instead of the default one (which is part of your git installation).

- 1,262,500
- 529
- 4,410
- 5,250
-
You sir are a champ! Excellent details (as always) and the fact that you edited an answer you gave 2 years ago!!! – dubes May 18 '16 at 07:33
-
@dubes I have added a bit more detail in this answer: http://stackoverflow.com/a/37293001/6309 – VonC May 18 '16 at 07:34
-
`A relative path is taken as relative to the directory where the hooks are run` Where are the hooks run? Glad the docs make that clear :/ – Jacob Thomason May 07 '17 at 01:24
-
-
@VonC. I added a relative path to the repo root and it's working properly. So, while you'd think that's the case, it's seemingly not the case. Regardless, I got it working by using a repo root relative path. – Jacob Thomason May 08 '17 at 15:13
-
@JacobThomason You are correct: I have edited the answer to point to the man page which does explain that clearly. – VonC May 08 '17 at 15:22