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