cweiske cweiske - 1 month ago 10x
Git Question

Find path to git hooks directory on the shell

How do I find the full path to the

directory of the current Git repository?

I see the following issues:

Deep in the directory structure

I may be anywhere deep in the git repository directory structure, e.g.


and I am in folder



Newer git versions put submodule meta data not into
but in the main repository and
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


qqx qqx

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