Hooks are specific to a particular clone of a repository, and as such, it's not possible to force them to be specified from a remote repository, like on GitHub. Git doesn't allow you to specify hooks in a repository because they can execute arbitrary code, and allowing you to do that would be a security vulnerability.
If you wanted to provide a set of hooks for developers to use, you could provide a repository with them and then add a script to set core.hooksPath
in the global config, which is the location of hooks if it is specified.
However, as outlined in the Git FAQ, you cannot rely on hooks as an effective control, because individual developers can bypass them trivially without being noticed. If you need to enforce policy, it will have to be done on the server side, with a CI job (or, on GitHub Enterprise Server only, a pre-receive
hook).
The FAQ mentions this downside of mandatory hooks as well:
In addition, some advanced users find pre-commit hooks to be an impediment to workflows that use temporary commits to stage work in progress or that create fixup commits, so it’s better to push these kinds of checks to the server anyway.
Option pre-commit
hooks can be a helpful tool for developers who wish to use them, though, and you could legitimately provide some suggested options for users who opt in.