Documentation / githooks.txton commit githooks.txt: minor improvements to the grammar & phrasing (de0824e)
   1githooks(5)
   2===========
   3
   4NAME
   5----
   6githooks - Hooks used by Git
   7
   8SYNOPSIS
   9--------
  10$GIT_DIR/hooks/*
  11
  12
  13DESCRIPTION
  14-----------
  15
  16Hooks are programs you can place in the `$GIT_DIR/hooks` directory to
  17trigger actions at certain points in git's execution. Hooks that don't
  18have the executable bit set are ignored.
  19
  20Before Git invokes a hook, it changes its working directory to either
  21the root of the working tree in a non-bare repository, or to the
  22$GIT_DIR in a bare repository.
  23
  24Hooks can get their arguments via the environment, command-line
  25arguments, and stdin. See the documentation for each hook below for
  26details.
  27
  28'git init' may copy hooks to the new repository, depending on its
  29configuration. See the "TEMPLATE DIRECTORY" section in
  30linkgit:git-init[1] for details. When the rest of this document refers
  31to "default hooks" it's talking about the default template shipped
  32with Git.
  33
  34The currently supported hooks are described below.
  35
  36HOOKS
  37-----
  38
  39applypatch-msg
  40~~~~~~~~~~~~~~
  41
  42This hook is invoked by 'git am'.  It takes a single
  43parameter, the name of the file that holds the proposed commit
  44log message.  Exiting with a non-zero status causes 'git am' to abort
  45before applying the patch.
  46
  47The hook is allowed to edit the message file in place, and can
  48be used to normalize the message into some project standard
  49format. It can also be used to refuse the commit after inspecting
  50the message file.
  51
  52The default 'applypatch-msg' hook, when enabled, runs the
  53'commit-msg' hook, if the latter is enabled.
  54
  55pre-applypatch
  56~~~~~~~~~~~~~~
  57
  58This hook is invoked by 'git am'.  It takes no parameter, and is
  59invoked after the patch is applied, but before a commit is made.
  60
  61If it exits with non-zero status, then the working tree will not be
  62committed after applying the patch.
  63
  64It can be used to inspect the current working tree and refuse to
  65make a commit if it does not pass certain test.
  66
  67The default 'pre-applypatch' hook, when enabled, runs the
  68'pre-commit' hook, if the latter is enabled.
  69
  70post-applypatch
  71~~~~~~~~~~~~~~~
  72
  73This hook is invoked by 'git am'.  It takes no parameter,
  74and is invoked after the patch is applied and a commit is made.
  75
  76This hook is meant primarily for notification, and cannot affect
  77the outcome of 'git am'.
  78
  79pre-commit
  80~~~~~~~~~~
  81
  82This hook is invoked by 'git commit', and can be bypassed
  83with the `--no-verify` option.  It takes no parameters, and is
  84invoked before obtaining the proposed commit log message and
  85making a commit.  Exiting with a non-zero status from this script
  86causes the 'git commit' command to abort before creating a commit.
  87
  88The default 'pre-commit' hook, when enabled, catches introduction
  89of lines with trailing whitespaces and aborts the commit when
  90such a line is found.
  91
  92All the 'git commit' hooks are invoked with the environment
  93variable `GIT_EDITOR=:` if the command will not bring up an editor
  94to modify the commit message.
  95
  96prepare-commit-msg
  97~~~~~~~~~~~~~~~~~~
  98
  99This hook is invoked by 'git commit' right after preparing the
 100default log message, and before the editor is started.
 101
 102It takes one to three parameters.  The first is the name of the file
 103that contains the commit log message.  The second is the source of the commit
 104message, and can be: `message` (if a `-m` or `-F` option was
 105given); `template` (if a `-t` option was given or the
 106configuration option `commit.template` is set); `merge` (if the
 107commit is a merge or a `.git/MERGE_MSG` file exists); `squash`
 108(if a `.git/SQUASH_MSG` file exists); or `commit`, followed by
 109a commit SHA-1 (if a `-c`, `-C` or `--amend` option was given).
 110
 111If the exit status is non-zero, 'git commit' will abort.
 112
 113The purpose of the hook is to edit the message file in place, and
 114it is not suppressed by the `--no-verify` option.  A non-zero exit
 115means a failure of the hook and aborts the commit.  It should not
 116be used as replacement for pre-commit hook.
 117
 118The sample `prepare-commit-msg` hook that comes with Git comments
 119out the `Conflicts:` part of a merge's commit message.
 120
 121commit-msg
 122~~~~~~~~~~
 123
 124This hook is invoked by 'git commit', and can be bypassed
 125with the `--no-verify` option.  It takes a single parameter, the
 126name of the file that holds the proposed commit log message.
 127Exiting with a non-zero status causes the 'git commit' to
 128abort.
 129
 130The hook is allowed to edit the message file in place, and can be used
 131to normalize the message into some project standard format. It
 132can also be used to refuse the commit after inspecting the message
 133file.
 134
 135The default 'commit-msg' hook, when enabled, detects duplicate
 136"Signed-off-by" lines, and aborts the commit if one is found.
 137
 138post-commit
 139~~~~~~~~~~~
 140
 141This hook is invoked by 'git commit'. It takes no parameters, and is
 142invoked after a commit is made.
 143
 144This hook is meant primarily for notification, and cannot affect
 145the outcome of 'git commit'.
 146
 147pre-rebase
 148~~~~~~~~~~
 149
 150This hook is called by 'git rebase' and can be used to prevent a
 151branch from getting rebased.  The hook may be called with one or
 152two parameters.  The first parameter is the upstream from which
 153the series was forked.  The second parameter is the branch being
 154rebased, and is not set when rebasing the current branch.
 155
 156post-checkout
 157~~~~~~~~~~~~~
 158
 159This hook is invoked when a 'git checkout' is run after having updated the
 160worktree.  The hook is given three parameters: the ref of the previous HEAD,
 161the ref of the new HEAD (which may or may not have changed), and a flag
 162indicating whether the checkout was a branch checkout (changing branches,
 163flag=1) or a file checkout (retrieving a file from the index, flag=0).
 164This hook cannot affect the outcome of 'git checkout'.
 165
 166It is also run after 'git clone', unless the --no-checkout (-n) option is
 167used. The first parameter given to the hook is the null-ref, the second the
 168ref of the new HEAD and the flag is always 1.
 169
 170This hook can be used to perform repository validity checks, auto-display
 171differences from the previous HEAD if different, or set working dir metadata
 172properties.
 173
 174post-merge
 175~~~~~~~~~~
 176
 177This hook is invoked by 'git merge', which happens when a 'git pull'
 178is done on a local repository.  The hook takes a single parameter, a status
 179flag specifying whether or not the merge being done was a squash merge.
 180This hook cannot affect the outcome of 'git merge' and is not executed,
 181if the merge failed due to conflicts.
 182
 183This hook can be used in conjunction with a corresponding pre-commit hook to
 184save and restore any form of metadata associated with the working tree
 185(e.g.: permissions/ownership, ACLS, etc).  See contrib/hooks/setgitperms.perl
 186for an example of how to do this.
 187
 188pre-push
 189~~~~~~~~
 190
 191This hook is called by 'git push' and can be used to prevent a push from taking
 192place.  The hook is called with two parameters which provide the name and
 193location of the destination remote, if a named remote is not being used both
 194values will be the same.
 195
 196Information about what is to be pushed is provided on the hook's standard
 197input with lines of the form:
 198
 199  <local ref> SP <local sha1> SP <remote ref> SP <remote sha1> LF
 200
 201For instance, if the command +git push origin master:foreign+ were run the
 202hook would receive a line like the following:
 203
 204  refs/heads/master 67890 refs/heads/foreign 12345
 205
 206although the full, 40-character SHA-1s would be supplied.  If the foreign ref
 207does not yet exist the `<remote SHA-1>` will be 40 `0`.  If a ref is to be
 208deleted, the `<local ref>` will be supplied as `(delete)` and the `<local
 209SHA-1>` will be 40 `0`.  If the local commit was specified by something other
 210than a name which could be expanded (such as `HEAD~`, or a SHA-1) it will be
 211supplied as it was originally given.
 212
 213If this hook exits with a non-zero status, 'git push' will abort without
 214pushing anything.  Information about why the push is rejected may be sent
 215to the user by writing to standard error.
 216
 217[[pre-receive]]
 218pre-receive
 219~~~~~~~~~~~
 220
 221This hook is invoked by 'git-receive-pack' on the remote repository,
 222which happens when a 'git push' is done on a local repository.
 223Just before starting to update refs on the remote repository, the
 224pre-receive hook is invoked.  Its exit status determines the success
 225or failure of the update.
 226
 227This hook executes once for the receive operation. It takes no
 228arguments, but for each ref to be updated it receives on standard
 229input a line of the format:
 230
 231  <old-value> SP <new-value> SP <ref-name> LF
 232
 233where `<old-value>` is the old object name stored in the ref,
 234`<new-value>` is the new object name to be stored in the ref and
 235`<ref-name>` is the full name of the ref.
 236When creating a new ref, `<old-value>` is 40 `0`.
 237
 238If the hook exits with non-zero status, none of the refs will be
 239updated. If the hook exits with zero, updating of individual refs can
 240still be prevented by the <<update,'update'>> hook.
 241
 242Both standard output and standard error output are forwarded to
 243'git send-pack' on the other end, so you can simply `echo` messages
 244for the user.
 245
 246[[update]]
 247update
 248~~~~~~
 249
 250This hook is invoked by 'git-receive-pack' on the remote repository,
 251which happens when a 'git push' is done on a local repository.
 252Just before updating the ref on the remote repository, the update hook
 253is invoked.  Its exit status determines the success or failure of
 254the ref update.
 255
 256The hook executes once for each ref to be updated, and takes
 257three parameters:
 258
 259 - the name of the ref being updated,
 260 - the old object name stored in the ref,
 261 - and the new object name to be stored in the ref.
 262
 263A zero exit from the update hook allows the ref to be updated.
 264Exiting with a non-zero status prevents 'git-receive-pack'
 265from updating that ref.
 266
 267This hook can be used to prevent 'forced' update on certain refs by
 268making sure that the object name is a commit object that is a
 269descendant of the commit object named by the old object name.
 270That is, to enforce a "fast-forward only" policy.
 271
 272It could also be used to log the old..new status.  However, it
 273does not know the entire set of branches, so it would end up
 274firing one e-mail per ref when used naively, though.  The
 275<<post-receive,'post-receive'>> hook is more suited to that.
 276
 277In an environment that restricts the users' access only to git
 278commands over the wire, this hook can be used to implement access
 279control without relying on filesystem ownership and group
 280membership. See linkgit:git-shell[1] for how you might use the login
 281shell to restrict the user's access to only git commands.
 282
 283Both standard output and standard error output are forwarded to
 284'git send-pack' on the other end, so you can simply `echo` messages
 285for the user.
 286
 287The default 'update' hook, when enabled--and with
 288`hooks.allowunannotated` config option unset or set to false--prevents
 289unannotated tags to be pushed.
 290
 291[[post-receive]]
 292post-receive
 293~~~~~~~~~~~~
 294
 295This hook is invoked by 'git-receive-pack' on the remote repository,
 296which happens when a 'git push' is done on a local repository.
 297It executes on the remote repository once after all the refs have
 298been updated.
 299
 300This hook executes once for the receive operation.  It takes no
 301arguments, but gets the same information as the
 302<<pre-receive,'pre-receive'>>
 303hook does on its standard input.
 304
 305This hook does not affect the outcome of 'git-receive-pack', as it
 306is called after the real work is done.
 307
 308This supersedes the <<post-update,'post-update'>> hook in that it gets
 309both old and new values of all the refs in addition to their
 310names.
 311
 312Both standard output and standard error output are forwarded to
 313'git send-pack' on the other end, so you can simply `echo` messages
 314for the user.
 315
 316The default 'post-receive' hook is empty, but there is
 317a sample script `post-receive-email` provided in the `contrib/hooks`
 318directory in Git distribution, which implements sending commit
 319emails.
 320
 321[[post-update]]
 322post-update
 323~~~~~~~~~~~
 324
 325This hook is invoked by 'git-receive-pack' on the remote repository,
 326which happens when a 'git push' is done on a local repository.
 327It executes on the remote repository once after all the refs have
 328been updated.
 329
 330It takes a variable number of parameters, each of which is the
 331name of ref that was actually updated.
 332
 333This hook is meant primarily for notification, and cannot affect
 334the outcome of 'git-receive-pack'.
 335
 336The 'post-update' hook can tell what are the heads that were pushed,
 337but it does not know what their original and updated values are,
 338so it is a poor place to do log old..new. The
 339<<post-receive,'post-receive'>> hook does get both original and
 340updated values of the refs. You might consider it instead if you need
 341them.
 342
 343When enabled, the default 'post-update' hook runs
 344'git update-server-info' to keep the information used by dumb
 345transports (e.g., HTTP) up-to-date.  If you are publishing
 346a Git repository that is accessible via HTTP, you should
 347probably enable this hook.
 348
 349Both standard output and standard error output are forwarded to
 350'git send-pack' on the other end, so you can simply `echo` messages
 351for the user.
 352
 353push-to-checkout
 354~~~~~~~~~~~~~~~~
 355
 356This hook is invoked by 'git-receive-pack' on the remote repository,
 357which happens when a 'git push' is done on a local repository, when
 358the push tries to update the branch that is currently checked out
 359and the `receive.denyCurrentBranch` configuration variable is set to
 360`updateInstead`.  Such a push by default is refused if the working
 361tree and the index of the remote repository has any difference from
 362the currently checked out commit; when both the working tree and the
 363index match the current commit, they are updated to match the newly
 364pushed tip of the branch.  This hook is to be used to override the
 365default behaviour.
 366
 367The hook receives the commit with which the tip of the current
 368branch is going to be updated.  It can exit with a non-zero status
 369to refuse the push (when it does so, it must not modify the index or
 370the working tree).  Or it can make any necessary changes to the
 371working tree and to the index to bring them to the desired state
 372when the tip of the current branch is updated to the new commit, and
 373exit with a zero status.
 374
 375For example, the hook can simply run `git read-tree -u -m HEAD "$1"`
 376in order to emulate 'git fetch' that is run in the reverse direction
 377with `git push`, as the two-tree form of `read-tree -u -m` is
 378essentially the same as `git checkout` that switches branches while
 379keeping the local changes in the working tree that do not interfere
 380with the difference between the branches.
 381
 382
 383pre-auto-gc
 384~~~~~~~~~~~
 385
 386This hook is invoked by 'git gc --auto'. It takes no parameter, and
 387exiting with non-zero status from this script causes the 'git gc --auto'
 388to abort.
 389
 390post-rewrite
 391~~~~~~~~~~~~
 392
 393This hook is invoked by commands that rewrite commits (`git commit
 394--amend`, 'git-rebase'; currently 'git-filter-branch' does 'not' call
 395it!).  Its first argument denotes the command it was invoked by:
 396currently one of `amend` or `rebase`.  Further command-dependent
 397arguments may be passed in the future.
 398
 399The hook receives a list of the rewritten commits on stdin, in the
 400format
 401
 402  <old-sha1> SP <new-sha1> [ SP <extra-info> ] LF
 403
 404The 'extra-info' is again command-dependent.  If it is empty, the
 405preceding SP is also omitted.  Currently, no commands pass any
 406'extra-info'.
 407
 408The hook always runs after the automatic note copying (see
 409"notes.rewrite.<command>" in linkgit:git-config[1]) has happened, and
 410thus has access to these notes.
 411
 412The following command-specific comments apply:
 413
 414rebase::
 415        For the 'squash' and 'fixup' operation, all commits that were
 416        squashed are listed as being rewritten to the squashed commit.
 417        This means that there will be several lines sharing the same
 418        'new-sha1'.
 419+
 420The commits are guaranteed to be listed in the order that they were
 421processed by rebase.
 422
 423
 424GIT
 425---
 426Part of the linkgit:git[1] suite