50.1. Usage of Git hooks
Git provides commit hooks, e.g., programs which can be executed at a pre-defined point during the work with the repository. For example, you can ensure that the commit message has a certain format or trigger an action after a push to the server.
These programs are usually scripts and can be written in any language, e.g., as shell scripts or in Perl, Python etc. You can also implement a hook, for example, in C and use the resulting executables. Git calls the scripts based on a naming convention.
50.2. Client and server side commit hooks
Git provides hooks for the client and for the server side. On the server side you can use the
pre-receive
and post-receive
script to check the input or to trigger actions after the commit. The usage of a server commit hook requires that you have access to the server. Hosting providers like GitHub or Bitbucket do not offer this access.
If you create a new Git repository, Git creates example scripts in the
.git/hooks
directory. The example scripts end with .sample
. To activate them make them executable and remove the .sample
from the filename.
50.3. Restrictions
Not all Git server implementations support server side commit hooks. For example Gerrit (a Git server which also provides the ability to do code review) does not support hooks in this form. Also Github and Bitbucket do not support server hooks at the time of this writing.
Local hooks in the local repository can be removed by the developer.
0 comments:
Post a Comment