Home Explore Blog CI



git

3rd chunk of `Documentation/githooks.adoc`
37c00c02423df495f4c75a0e05873f4bff1a52d6a4ca759b0000000100000fa3
 template.

commit-msg
~~~~~~~~~~

This hook is invoked by linkgit:git-commit[1] and linkgit:git-merge[1], and can be
bypassed with the `--no-verify` option.  It takes a single parameter,
the name of the file that holds the proposed commit log message.
Exiting with a non-zero status causes the command to abort.

The hook is allowed to edit the message file in place, and can be used
to normalize the message into some project standard format. It
can also be used to refuse the commit after inspecting the message
file.

The default 'commit-msg' hook, when enabled, detects duplicate
`Signed-off-by` trailers, and aborts the commit if one is found.

post-commit
~~~~~~~~~~~

This hook is invoked by linkgit:git-commit[1]. It takes no parameters, and is
invoked after a commit is made.

This hook is meant primarily for notification, and cannot affect
the outcome of `git commit`.

pre-rebase
~~~~~~~~~~

This hook is called by linkgit:git-rebase[1] and can be used to prevent a
branch from getting rebased.  The hook may be called with one or
two parameters.  The first parameter is the upstream from which
the series was forked.  The second parameter is the branch being
rebased, and is not set when rebasing the current branch.

post-checkout
~~~~~~~~~~~~~

This hook is invoked when a linkgit:git-checkout[1] or
linkgit:git-switch[1] is run after having updated the
worktree.  The hook is given three parameters: the ref of the previous HEAD,
the ref of the new HEAD (which may or may not have changed), and a flag
indicating whether the checkout was a branch checkout (changing branches,
flag=1) or a file checkout (retrieving a file from the index, flag=0).
This hook cannot affect the outcome of `git switch` or `git checkout`,
other than that the hook's exit status becomes the exit status of
these two commands.

It is also run after linkgit:git-clone[1], unless the `--no-checkout` (`-n`) option is
used. The first parameter given to the hook is the null-ref, the second the
ref of the new HEAD and the flag is always 1. Likewise for `git worktree add`
unless `--no-checkout` is used.

This hook can be used to perform repository validity checks, auto-display
differences from the previous HEAD if different, or set working dir metadata
properties.

post-merge
~~~~~~~~~~

This hook is invoked by linkgit:git-merge[1], which happens when a `git pull`
is done on a local repository.  The hook takes a single parameter, a status
flag specifying whether or not the merge being done was a squash merge.
This hook cannot affect the outcome of `git merge` and is not executed,
if the merge failed due to conflicts.

This hook can be used in conjunction with a corresponding pre-commit hook to
save and restore any form of metadata associated with the working tree
(e.g.: permissions/ownership, ACLS, etc).  See contrib/hooks/setgitperms.perl
for an example of how to do this.

pre-push
~~~~~~~~

This hook is called by linkgit:git-push[1] and can be used to prevent
a push from taking place.  The hook is called with two parameters
which provide the name and location of the destination remote, if a
named remote is not being used both values will be the same.

Information about what is to be pushed is provided on the hook's standard
input with lines of the form:

  <local-ref> SP <local-object-name> SP <remote-ref> SP <remote-object-name> LF

For instance, if the command +git push origin master:foreign+ were run the
hook would receive a line like the following:

  refs/heads/master 67890 refs/heads/foreign 12345

although the full object name would be supplied.  If the foreign ref does not
yet exist the `<remote-object-name>` will be the all-zeroes object name.  If a
ref is to be deleted, the `<local-ref>` will be supplied as `(delete)` and the
`<local-object-name>` will be the all-zeroes object name.  If the local commit
was specified by something other than a name which could be expanded (such as
`HEAD~`, or an object name) it will be supplied as it was originally given.

If this

Title: Git Hooks for Repository Management and Validation
Summary
Git provides various hooks for repository management and validation, including commit-msg, post-commit, pre-rebase, post-checkout, post-merge, and pre-push, which can be used to enforce project standards, perform repository validity checks, and prevent certain actions such as rebasing or pushing. These hooks can be used to normalize commit messages, detect duplicate trailers, and save and restore metadata associated with the working tree, and are invoked at different points during the Git workflow, providing flexibility and customization options for repository management.