Why is the .git repository not part of any branch? When I create new git hooks are they not tracked within git itself?
Asked
Active
Viewed 127 times
0
-
https://stackoverflow.com/search?q=%5Bgit%5D+track+hooks – phd Apr 09 '19 at 13:19
1 Answers
2
It is a special directory that Git ignores in a repository, as it contains the information about the repository itself.
So no, hooks that you place is .git/hooks
are not tracked within your project.
However, you can for example do the following:
In your project, create a hooks directory and place them here. Then, in .git/hooks
create the hooks a symbolic links pointing towards those in your repo. It'd look as follow:
├── .git
│ ├── config
│ ├── HEAD
│ ├── hooks
│ │ └── pre-commit -> ../../hooks/pre-commit
│ ├── objects
│ │ ├── info
│ │ └── pack
│ └── refs
│ ├── heads
│ └── tags
└── hooks
└── pre-commit
So you can keep them versioned within your project.
If you want to have more global hooks to use across repositories, you can use templates, I wrote an article about how to set it up: https://www.ghislain-rodrigues.fr/articles/git-hooks-template.html

padawin
- 4,230
- 15
- 19