1GITHOOKS(5)                       Git Manual                       GITHOOKS(5)
2
3
4

NAME

6       githooks - Hooks used by Git
7

SYNOPSIS

9       $GIT_DIR/hooks/* (or `git config core.hooksPath`/*)
10

DESCRIPTION

12       Hooks are programs you can place in a hooks directory to trigger
13       actions at certain points in git’s execution. Hooks that don’t have the
14       executable bit set are ignored.
15
16       By default the hooks directory is $GIT_DIR/hooks, but that can be
17       changed via the core.hooksPath configuration variable (see git-
18       config(1)).
19
20       Before Git invokes a hook, it changes its working directory to either
21       $GIT_DIR in a bare repository or the root of the working tree in a
22       non-bare repository. An exception are hooks triggered during a push
23       (pre-receive, update, post-receive, post-update, push-to-checkout)
24       which are always executed in $GIT_DIR.
25
26       Hooks can get their arguments via the environment, command-line
27       arguments, and stdin. See the documentation for each hook below for
28       details.
29
30       git init may copy hooks to the new repository, depending on its
31       configuration. See the "TEMPLATE DIRECTORY" section in git-init(1) for
32       details. When the rest of this document refers to "default hooks" it’s
33       talking about the default template shipped with Git.
34
35       The currently supported hooks are described below.
36

HOOKS

38   applypatch-msg
39       This hook is invoked by git-am(1). It takes a single parameter, the
40       name of the file that holds the proposed commit log message. Exiting
41       with a non-zero status causes git am to abort before applying the
42       patch.
43
44       The hook is allowed to edit the message file in place, and can be used
45       to normalize the message into some project standard format. It can also
46       be used to refuse the commit after inspecting the message file.
47
48       The default applypatch-msg hook, when enabled, runs the commit-msg
49       hook, if the latter is enabled.
50
51   pre-applypatch
52       This hook is invoked by git-am(1). It takes no parameter, and is
53       invoked after the patch is applied, but before a commit is made.
54
55       If it exits with non-zero status, then the working tree will not be
56       committed after applying the patch.
57
58       It can be used to inspect the current working tree and refuse to make a
59       commit if it does not pass certain test.
60
61       The default pre-applypatch hook, when enabled, runs the pre-commit
62       hook, if the latter is enabled.
63
64   post-applypatch
65       This hook is invoked by git-am(1). It takes no parameter, and is
66       invoked after the patch is applied and a commit is made.
67
68       This hook is meant primarily for notification, and cannot affect the
69       outcome of git am.
70
71   pre-commit
72       This hook is invoked by git-commit(1), and can be bypassed with the
73       --no-verify option. It takes no parameters, and is invoked before
74       obtaining the proposed commit log message and making a commit. Exiting
75       with a non-zero status from this script causes the git commit command
76       to abort before creating a commit.
77
78       The default pre-commit hook, when enabled, catches introduction of
79       lines with trailing whitespaces and aborts the commit when such a line
80       is found.
81
82       All the git commit hooks are invoked with the environment variable
83       GIT_EDITOR=: if the command will not bring up an editor to modify the
84       commit message.
85
86       The default pre-commit hook, when enabled—and with the
87       hooks.allownonascii config option unset or set to false—prevents the
88       use of non-ASCII filenames.
89
90   pre-merge-commit
91       This hook is invoked by git-merge(1), and can be bypassed with the
92       --no-verify option. It takes no parameters, and is invoked after the
93       merge has been carried out successfully and before obtaining the
94       proposed commit log message to make a commit. Exiting with a non-zero
95       status from this script causes the git merge command to abort before
96       creating a commit.
97
98       The default pre-merge-commit hook, when enabled, runs the pre-commit
99       hook, if the latter is enabled.
100
101       This hook is invoked with the environment variable GIT_EDITOR=: if the
102       command will not bring up an editor to modify the commit message.
103
104       If the merge cannot be carried out automatically, the conflicts need to
105       be resolved and the result committed separately (see git-merge(1)). At
106       that point, this hook will not be executed, but the pre-commit hook
107       will, if it is enabled.
108
109   prepare-commit-msg
110       This hook is invoked by git-commit(1) right after preparing the default
111       log message, and before the editor is started.
112
113       It takes one to three parameters. The first is the name of the file
114       that contains the commit log message. The second is the source of the
115       commit message, and can be: message (if a -m or -F option was given);
116       template (if a -t option was given or the configuration option
117       commit.template is set); merge (if the commit is a merge or a
118       .git/MERGE_MSG file exists); squash (if a .git/SQUASH_MSG file exists);
119       or commit, followed by a commit SHA-1 (if a -c, -C or --amend option
120       was given).
121
122       If the exit status is non-zero, git commit will abort.
123
124       The purpose of the hook is to edit the message file in place, and it is
125       not suppressed by the --no-verify option. A non-zero exit means a
126       failure of the hook and aborts the commit. It should not be used as
127       replacement for pre-commit hook.
128
129       The sample prepare-commit-msg hook that comes with Git removes the help
130       message found in the commented portion of the commit template.
131
132   commit-msg
133       This hook is invoked by git-commit(1) and git-merge(1), and can be
134       bypassed with the --no-verify option. It takes a single parameter, the
135       name of the file that holds the proposed commit log message. Exiting
136       with a non-zero status causes the command to abort.
137
138       The hook is allowed to edit the message file in place, and can be used
139       to normalize the message into some project standard format. It can also
140       be used to refuse the commit after inspecting the message file.
141
142       The default commit-msg hook, when enabled, detects duplicate
143       "Signed-off-by" lines, and aborts the commit if one is found.
144
145   post-commit
146       This hook is invoked by git-commit(1). It takes no parameters, and is
147       invoked after a commit is made.
148
149       This hook is meant primarily for notification, and cannot affect the
150       outcome of git commit.
151
152   pre-rebase
153       This hook is called by git-rebase(1) and can be used to prevent a
154       branch from getting rebased. The hook may be called with one or two
155       parameters. The first parameter is the upstream from which the series
156       was forked. The second parameter is the branch being rebased, and is
157       not set when rebasing the current branch.
158
159   post-checkout
160       This hook is invoked when a git-checkout(1) or git-switch(1) is run
161       after having updated the worktree. The hook is given three parameters:
162       the ref of the previous HEAD, the ref of the new HEAD (which may or may
163       not have changed), and a flag indicating whether the checkout was a
164       branch checkout (changing branches, flag=1) or a file checkout
165       (retrieving a file from the index, flag=0). This hook cannot affect the
166       outcome of git switch or git checkout.
167
168       It is also run after git-clone(1), unless the --no-checkout (-n) option
169       is used. The first parameter given to the hook is the null-ref, the
170       second the ref of the new HEAD and the flag is always 1. Likewise for
171       git worktree add unless --no-checkout is used.
172
173       This hook can be used to perform repository validity checks,
174       auto-display differences from the previous HEAD if different, or set
175       working dir metadata properties.
176
177   post-merge
178       This hook is invoked by git-merge(1), which happens when a git pull is
179       done on a local repository. The hook takes a single parameter, a status
180       flag specifying whether or not the merge being done was a squash merge.
181       This hook cannot affect the outcome of git merge and is not executed,
182       if the merge failed due to conflicts.
183
184       This hook can be used in conjunction with a corresponding pre-commit
185       hook to save and restore any form of metadata associated with the
186       working tree (e.g.: permissions/ownership, ACLS, etc). See
187       contrib/hooks/setgitperms.perl for an example of how to do this.
188
189   pre-push
190       This hook is called by git-push(1) and can be used to prevent a push
191       from taking place. The hook is called with two parameters which provide
192       the name and location of the destination remote, if a named remote is
193       not being used both values will be the same.
194
195       Information about what is to be pushed is provided on the hook’s
196       standard input with lines of the form:
197
198           <local ref> SP <local sha1> SP <remote ref> SP <remote sha1> LF
199
200       For instance, if the command git push origin master:foreign were run
201       the hook would receive a line like the following:
202
203           refs/heads/master 67890 refs/heads/foreign 12345
204
205       although the full, 40-character SHA-1s would be supplied. If the
206       foreign ref does not yet exist the <remote SHA-1> will be 40 0. If a
207       ref is to be deleted, the <local ref> will be supplied as (delete) and
208       the <local SHA-1> will be 40 0. If the local commit was specified by
209       something other than a name which could be expanded (such as HEAD~, or
210       a SHA-1) it will be supplied as it was originally given.
211
212       If this hook exits with a non-zero status, git push will abort without
213       pushing anything. Information about why the push is rejected may be
214       sent to the user by writing to standard error.
215
216   pre-receive
217       This hook is invoked by git-receive-pack(1) when it reacts to git push
218       and updates reference(s) in its repository. Just before starting to
219       update refs on the remote repository, the pre-receive hook is invoked.
220       Its exit status determines the success or failure of the update.
221
222       This hook executes once for the receive operation. It takes no
223       arguments, but for each ref to be updated it receives on standard input
224       a line of the format:
225
226           <old-value> SP <new-value> SP <ref-name> LF
227
228       where <old-value> is the old object name stored in the ref, <new-value>
229       is the new object name to be stored in the ref and <ref-name> is the
230       full name of the ref. When creating a new ref, <old-value> is 40 0.
231
232       If the hook exits with non-zero status, none of the refs will be
233       updated. If the hook exits with zero, updating of individual refs can
234       still be prevented by the update hook.
235
236       Both standard output and standard error output are forwarded to git
237       send-pack on the other end, so you can simply echo messages for the
238       user.
239
240       The number of push options given on the command line of git push
241       --push-option=... can be read from the environment variable
242       GIT_PUSH_OPTION_COUNT, and the options themselves are found in
243       GIT_PUSH_OPTION_0, GIT_PUSH_OPTION_1,... If it is negotiated to not use
244       the push options phase, the environment variables will not be set. If
245       the client selects to use push options, but doesn’t transmit any, the
246       count variable will be set to zero, GIT_PUSH_OPTION_COUNT=0.
247
248       See the section on "Quarantine Environment" in git-receive-pack(1) for
249       some caveats.
250
251   update
252       This hook is invoked by git-receive-pack(1) when it reacts to git push
253       and updates reference(s) in its repository. Just before updating the
254       ref on the remote repository, the update hook is invoked. Its exit
255       status determines the success or failure of the ref update.
256
257       The hook executes once for each ref to be updated, and takes three
258       parameters:
259
260       ·   the name of the ref being updated,
261
262       ·   the old object name stored in the ref,
263
264       ·   and the new object name to be stored in the ref.
265
266       A zero exit from the update hook allows the ref to be updated. Exiting
267       with a non-zero status prevents git receive-pack from updating that
268       ref.
269
270       This hook can be used to prevent forced update on certain refs by
271       making sure that the object name is a commit object that is a
272       descendant of the commit object named by the old object name. That is,
273       to enforce a "fast-forward only" policy.
274
275       It could also be used to log the old..new status. However, it does not
276       know the entire set of branches, so it would end up firing one e-mail
277       per ref when used naively, though. The post-receive hook is more suited
278       to that.
279
280       In an environment that restricts the users' access only to git commands
281       over the wire, this hook can be used to implement access control
282       without relying on filesystem ownership and group membership. See git-
283       shell(1) for how you might use the login shell to restrict the user’s
284       access to only git commands.
285
286       Both standard output and standard error output are forwarded to git
287       send-pack on the other end, so you can simply echo messages for the
288       user.
289
290       The default update hook, when enabled—and with hooks.allowunannotated
291       config option unset or set to false—prevents unannotated tags to be
292       pushed.
293
294   post-receive
295       This hook is invoked by git-receive-pack(1) when it reacts to git push
296       and updates reference(s) in its repository. It executes on the remote
297       repository once after all the refs have been updated.
298
299       This hook executes once for the receive operation. It takes no
300       arguments, but gets the same information as the pre-receive hook does
301       on its standard input.
302
303       This hook does not affect the outcome of git receive-pack, as it is
304       called after the real work is done.
305
306       This supersedes the post-update hook in that it gets both old and new
307       values of all the refs in addition to their names.
308
309       Both standard output and standard error output are forwarded to git
310       send-pack on the other end, so you can simply echo messages for the
311       user.
312
313       The default post-receive hook is empty, but there is a sample script
314       post-receive-email provided in the contrib/hooks directory in Git
315       distribution, which implements sending commit emails.
316
317       The number of push options given on the command line of git push
318       --push-option=... can be read from the environment variable
319       GIT_PUSH_OPTION_COUNT, and the options themselves are found in
320       GIT_PUSH_OPTION_0, GIT_PUSH_OPTION_1,... If it is negotiated to not use
321       the push options phase, the environment variables will not be set. If
322       the client selects to use push options, but doesn’t transmit any, the
323       count variable will be set to zero, GIT_PUSH_OPTION_COUNT=0.
324
325   post-update
326       This hook is invoked by git-receive-pack(1) when it reacts to git push
327       and updates reference(s) in its repository. It executes on the remote
328       repository once after all the refs have been updated.
329
330       It takes a variable number of parameters, each of which is the name of
331       ref that was actually updated.
332
333       This hook is meant primarily for notification, and cannot affect the
334       outcome of git receive-pack.
335
336       The post-update hook can tell what are the heads that were pushed, but
337       it does not know what their original and updated values are, so it is a
338       poor place to do log old..new. The post-receive hook does get both
339       original and updated values of the refs. You might consider it instead
340       if you need them.
341
342       When enabled, the default post-update hook runs git update-server-info
343       to keep the information used by dumb transports (e.g., HTTP) up to
344       date. If you are publishing a Git repository that is accessible via
345       HTTP, you should probably enable this hook.
346
347       Both standard output and standard error output are forwarded to git
348       send-pack on the other end, so you can simply echo messages for the
349       user.
350
351   push-to-checkout
352       This hook is invoked by git-receive-pack(1) when it reacts to git push
353       and updates reference(s) in its repository, and when the push tries to
354       update the branch that is currently checked out and the
355       receive.denyCurrentBranch configuration variable is set to
356       updateInstead. Such a push by default is refused if the working tree
357       and the index of the remote repository has any difference from the
358       currently checked out commit; when both the working tree and the index
359       match the current commit, they are updated to match the newly pushed
360       tip of the branch. This hook is to be used to override the default
361       behaviour.
362
363       The hook receives the commit with which the tip of the current branch
364       is going to be updated. It can exit with a non-zero status to refuse
365       the push (when it does so, it must not modify the index or the working
366       tree). Or it can make any necessary changes to the working tree and to
367       the index to bring them to the desired state when the tip of the
368       current branch is updated to the new commit, and exit with a zero
369       status.
370
371       For example, the hook can simply run git read-tree -u -m HEAD "$1" in
372       order to emulate git fetch that is run in the reverse direction with
373       git push, as the two-tree form of git read-tree -u -m is essentially
374       the same as git switch or git checkout that switches branches while
375       keeping the local changes in the working tree that do not interfere
376       with the difference between the branches.
377
378   pre-auto-gc
379       This hook is invoked by git gc --auto (see git-gc(1)). It takes no
380       parameter, and exiting with non-zero status from this script causes the
381       git gc --auto to abort.
382
383   post-rewrite
384       This hook is invoked by commands that rewrite commits (git-commit(1)
385       when called with --amend and git-rebase(1); however, full-history
386       (re)writing tools like git-fast-import(1) or git-filter-repo[1]
387       typically do not call it!). Its first argument denotes the command it
388       was invoked by: currently one of amend or rebase. Further
389       command-dependent arguments may be passed in the future.
390
391       The hook receives a list of the rewritten commits on stdin, in the
392       format
393
394           <old-sha1> SP <new-sha1> [ SP <extra-info> ] LF
395
396       The extra-info is again command-dependent. If it is empty, the
397       preceding SP is also omitted. Currently, no commands pass any
398       extra-info.
399
400       The hook always runs after the automatic note copying (see
401       "notes.rewrite.<command>" in git-config(1)) has happened, and thus has
402       access to these notes.
403
404       The following command-specific comments apply:
405
406       rebase
407           For the squash and fixup operation, all commits that were squashed
408           are listed as being rewritten to the squashed commit. This means
409           that there will be several lines sharing the same new-sha1.
410
411           The commits are guaranteed to be listed in the order that they were
412           processed by rebase.
413
414   sendemail-validate
415       This hook is invoked by git-send-email(1). It takes a single parameter,
416       the name of the file that holds the e-mail to be sent. Exiting with a
417       non-zero status causes git send-email to abort before sending any
418       e-mails.
419
420   fsmonitor-watchman
421       This hook is invoked when the configuration option core.fsmonitor is
422       set to .git/hooks/fsmonitor-watchman. It takes two arguments, a version
423       (currently 1) and the time in elapsed nanoseconds since midnight,
424       January 1, 1970.
425
426       The hook should output to stdout the list of all files in the working
427       directory that may have changed since the requested time. The logic
428       should be inclusive so that it does not miss any potential changes. The
429       paths should be relative to the root of the working directory and be
430       separated by a single NUL.
431
432       It is OK to include files which have not actually changed. All changes
433       including newly-created and deleted files should be included. When
434       files are renamed, both the old and the new name should be included.
435
436       Git will limit what files it checks for changes as well as which
437       directories are checked for untracked files based on the path names
438       given.
439
440       An optimized way to tell git "all files have changed" is to return the
441       filename /.
442
443       The exit status determines whether git will use the data from the hook
444       to limit its search. On error, it will fall back to verifying all files
445       and folders.
446
447   p4-pre-submit
448       This hook is invoked by git-p4 submit. It takes no parameters and
449       nothing from standard input. Exiting with non-zero status from this
450       script prevent git-p4 submit from launching. Run git-p4 submit --help
451       for details.
452
453   post-index-change
454       This hook is invoked when the index is written in read-cache.c
455       do_write_locked_index.
456
457       The first parameter passed to the hook is the indicator for the working
458       directory being updated. "1" meaning working directory was updated or
459       "0" when the working directory was not updated.
460
461       The second parameter passed to the hook is the indicator for whether or
462       not the index was updated and the skip-worktree bit could have changed.
463       "1" meaning skip-worktree bits could have been updated and "0" meaning
464       they were not.
465
466       Only one parameter should be set to "1" when the hook runs. The hook
467       running passing "1", "1" should not be possible.
468

GIT

470       Part of the git(1) suite
471

NOTES

473        1. git-filter-repo
474           https://github.com/newren/git-filter-repo
475
476
477
478Git 2.24.1                        12/10/2019                       GITHOOKS(5)
Impressum