How do I find the full path to the .git/hooks
directory of the current Git repository?
I see the following issues:
I may be anywhere deep in the git repository directory structure, e.g.
/home/user/project/.git/hooks
and I am in folder
/home/user/project/foo/bar/baz/
Newer git versions put submodule meta data not into .git/
but in the main repository and .git
is only a file, e.g.
$ cat /home/user/project/vendor/foo/.git
gitdir: ../../.git/modules/vendor/foo
So in this case, the hooks dir is in
/home/user/project/.git/modules/vendor/foo/hooks
The hooks are all stored in the hooks subdirectory of the Git directory. In most projects, that's . git/hooks .
Git hooks are shell scripts found in the hidden . git/hooks directory of a Git repository. These scripts trigger actions in response to specific events, so they can help you automate your development lifecycle. Although you may never have noticed them, every Git repository includes 12 sample scripts.
You can use git rev-parse --git-dir
to get the path to the repository used for your current directory. This will deal with gitlinks (using a file in place of the .git
directory) as well as having use of the $GIT_DIR
environment variable. The hooks directory will always be inside of that so you can use:
`git rev-parse --git-dir`/hooks
to get the path to the hooks directory.
This is documented in the git rev-parse manpage
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With