blob: 1c736738ccc91b6929226a27e02716221ec3ef05 [file] [log] [blame]
Junio C Hamano2fbcd212008-05-14 22:26:071githooks(5)
2===========
3
4NAME
5----
6githooks - Hooks used by git
7
8SYNOPSIS
9--------
10$GIT_DIR/hooks/*
11
12
13DESCRIPTION
14-----------
Junio C Hamano1a4e8412005-12-27 08:17:2315
16Hooks are little scripts you can place in `$GIT_DIR/hooks`
17directory to trigger action at certain points. When
Junio C Hamano6efe3022009-01-13 16:47:5618'git-init' is run, a handful of example hooks are copied into the
Junio C Hamano1a4e8412005-12-27 08:17:2319`hooks` directory of the new repository, but by default they are
Junio C Hamano6aff3992008-06-25 08:07:4420all disabled. To enable a hook, rename it by removing its `.sample`
21suffix.
Junio C Hamano1a4e8412005-12-27 08:17:2322
Junio C Hamano8a48fa22008-12-18 08:44:3023NOTE: It is also a requirement for a given hook to be executable.
24However - in a freshly initialized repository - the `.sample` files are
25executable by default.
26
Junio C Hamano1a4e8412005-12-27 08:17:2327This document describes the currently defined hooks.
28
29applypatch-msg
30--------------
31
Junio C Hamanoba4b9282008-07-06 05:20:3132This hook is invoked by 'git-am' script. It takes a single
Junio C Hamano1a4e8412005-12-27 08:17:2333parameter, the name of the file that holds the proposed commit
Junio C Hamanod5784132006-09-20 21:29:2734log message. Exiting with non-zero status causes
Junio C Hamanoba4b9282008-07-06 05:20:3135'git-am' to abort before applying the patch.
Junio C Hamano1a4e8412005-12-27 08:17:2336
37The hook is allowed to edit the message file in place, and can
38be used to normalize the message into some project standard
39format (if the project has one). It can also be used to refuse
40the commit after inspecting the message file.
41
Junio C Hamanod5784132006-09-20 21:29:2742The default 'applypatch-msg' hook, when enabled, runs the
43'commit-msg' hook, if the latter is enabled.
Junio C Hamano1a4e8412005-12-27 08:17:2344
45pre-applypatch
46--------------
47
Junio C Hamanoba4b9282008-07-06 05:20:3148This hook is invoked by 'git-am'. It takes no parameter, and is
Junio C Hamanoa31092a2008-05-04 06:41:2349invoked after the patch is applied, but before a commit is made.
50
51If it exits with non-zero status, then the working tree will not be
52committed after applying the patch.
Junio C Hamano1a4e8412005-12-27 08:17:2353
54It can be used to inspect the current working tree and refuse to
55make a commit if it does not pass certain test.
56
Junio C Hamanod5784132006-09-20 21:29:2757The default 'pre-applypatch' hook, when enabled, runs the
58'pre-commit' hook, if the latter is enabled.
Junio C Hamano1a4e8412005-12-27 08:17:2359
60post-applypatch
61---------------
62
Junio C Hamanoba4b9282008-07-06 05:20:3163This hook is invoked by 'git-am'. It takes no parameter,
Junio C Hamano1a4e8412005-12-27 08:17:2364and is invoked after the patch is applied and a commit is made.
65
66This hook is meant primarily for notification, and cannot affect
Junio C Hamanoba4b9282008-07-06 05:20:3167the outcome of 'git-am'.
Junio C Hamano1a4e8412005-12-27 08:17:2368
69pre-commit
70----------
71
Junio C Hamanoba4b9282008-07-06 05:20:3172This hook is invoked by 'git-commit', and can be bypassed
Junio C Hamano1a4e8412005-12-27 08:17:2373with `\--no-verify` option. It takes no parameter, and is
74invoked before obtaining the proposed commit log message and
75making a commit. Exiting with non-zero status from this script
Junio C Hamanoba4b9282008-07-06 05:20:3176causes the 'git-commit' to abort.
Junio C Hamano1a4e8412005-12-27 08:17:2377
Junio C Hamanod5784132006-09-20 21:29:2778The default 'pre-commit' hook, when enabled, catches introduction
Junio C Hamano1a4e8412005-12-27 08:17:2379of lines with trailing whitespaces and aborts the commit when
Junio C Hamanod5784132006-09-20 21:29:2780such a line is found.
Junio C Hamano1a4e8412005-12-27 08:17:2381
Junio C Hamanoba4b9282008-07-06 05:20:3182All the 'git-commit' hooks are invoked with the environment
Junio C Hamano26e590a2008-02-17 03:53:5183variable `GIT_EDITOR=:` if the command will not bring up an editor
84to modify the commit message.
85
86prepare-commit-msg
87------------------
88
Junio C Hamanoba4b9282008-07-06 05:20:3189This hook is invoked by 'git-commit' right after preparing the
Junio C Hamano26e590a2008-02-17 03:53:5190default log message, and before the editor is started.
91
92It takes one to three parameters. The first is the name of the file
Junio C Hamanobd53dbf2009-01-18 18:26:3793that contains the commit log message. The second is the source of the commit
Junio C Hamanoa476efa2008-10-10 15:31:4294message, and can be: `message` (if a `-m` or `-F` option was
95given); `template` (if a `-t` option was given or the
Junio C Hamano26e590a2008-02-17 03:53:5196configuration option `commit.template` is set); `merge` (if the
97commit is a merge or a `.git/MERGE_MSG` file exists); `squash`
98(if a `.git/SQUASH_MSG` file exists); or `commit`, followed by
Junio C Hamanoa476efa2008-10-10 15:31:4299a commit SHA1 (if a `-c`, `-C` or `\--amend` option was given).
Junio C Hamano26e590a2008-02-17 03:53:51100
Junio C Hamanoba4b9282008-07-06 05:20:31101If the exit status is non-zero, 'git-commit' will abort.
Junio C Hamano26e590a2008-02-17 03:53:51102
103The purpose of the hook is to edit the message file in place, and
104it is not suppressed by the `\--no-verify` option. A non-zero exit
105means a failure of the hook and aborts the commit. It should not
106be used as replacement for pre-commit hook.
107
108The sample `prepare-commit-msg` hook that comes with git comments
109out the `Conflicts:` part of a merge's commit message.
110
Junio C Hamano1a4e8412005-12-27 08:17:23111commit-msg
112----------
113
Junio C Hamanoba4b9282008-07-06 05:20:31114This hook is invoked by 'git-commit', and can be bypassed
Junio C Hamano1a4e8412005-12-27 08:17:23115with `\--no-verify` option. It takes a single parameter, the
116name of the file that holds the proposed commit log message.
Junio C Hamanoba4b9282008-07-06 05:20:31117Exiting with non-zero status causes the 'git-commit' to
Junio C Hamano1a4e8412005-12-27 08:17:23118abort.
119
120The hook is allowed to edit the message file in place, and can
121be used to normalize the message into some project standard
122format (if the project has one). It can also be used to refuse
123the commit after inspecting the message file.
124
Junio C Hamanod5784132006-09-20 21:29:27125The default 'commit-msg' hook, when enabled, detects duplicate
126"Signed-off-by" lines, and aborts the commit if one is found.
Junio C Hamano1a4e8412005-12-27 08:17:23127
128post-commit
129-----------
130
Junio C Hamanoba4b9282008-07-06 05:20:31131This hook is invoked by 'git-commit'. It takes no
Junio C Hamano1a4e8412005-12-27 08:17:23132parameter, and is invoked after a commit is made.
133
134This hook is meant primarily for notification, and cannot affect
Junio C Hamanoba4b9282008-07-06 05:20:31135the outcome of 'git-commit'.
Junio C Hamano1a4e8412005-12-27 08:17:23136
Junio C Hamanoa476efa2008-10-10 15:31:42137pre-rebase
138----------
139
140This hook is called by 'git-rebase' and can be used to prevent a branch
141from getting rebased.
142
143
Junio C Hamano1b50ce92007-10-03 12:05:53144post-checkout
145-----------
146
Junio C Hamanoba4b9282008-07-06 05:20:31147This hook is invoked when a 'git-checkout' is run after having updated the
Junio C Hamano1b50ce92007-10-03 12:05:53148worktree. The hook is given three parameters: the ref of the previous HEAD,
149the ref of the new HEAD (which may or may not have changed), and a flag
150indicating whether the checkout was a branch checkout (changing branches,
151flag=1) or a file checkout (retrieving a file from the index, flag=0).
Junio C Hamanoba4b9282008-07-06 05:20:31152This hook cannot affect the outcome of 'git-checkout'.
Junio C Hamano1b50ce92007-10-03 12:05:53153
Junio C Hamano36a56722009-03-28 08:55:34154It is also run after 'git-clone', unless the --no-checkout (-n) option is
155used. The first parameter given to the hook is the null-ref, the second the
156ref of the new HEAD and the flag is always 1.
157
Junio C Hamano1b50ce92007-10-03 12:05:53158This hook can be used to perform repository validity checks, auto-display
159differences from the previous HEAD if different, or set working dir metadata
160properties.
161
Junio C Hamano01d8f832007-09-24 07:37:30162post-merge
163-----------
164
Junio C Hamanoba4b9282008-07-06 05:20:31165This hook is invoked by 'git-merge', which happens when a 'git-pull'
Junio C Hamano01d8f832007-09-24 07:37:30166is done on a local repository. The hook takes a single parameter, a status
167flag specifying whether or not the merge being done was a squash merge.
Junio C Hamanoba4b9282008-07-06 05:20:31168This hook cannot affect the outcome of 'git-merge' and is not executed,
Junio C Hamano47d68a52008-05-06 06:35:40169if the merge failed due to conflicts.
Junio C Hamano01d8f832007-09-24 07:37:30170
171This hook can be used in conjunction with a corresponding pre-commit hook to
172save and restore any form of metadata associated with the working tree
173(eg: permissions/ownership, ACLS, etc). See contrib/hooks/setgitperms.perl
174for an example of how to do this.
175
Junio C Hamano8638c922007-05-12 20:50:08176[[pre-receive]]
177pre-receive
178-----------
179
Junio C Hamanoba4b9282008-07-06 05:20:31180This hook is invoked by 'git-receive-pack' on the remote repository,
181which happens when a 'git-push' is done on a local repository.
Junio C Hamano8638c922007-05-12 20:50:08182Just before starting to update refs on the remote repository, the
183pre-receive hook is invoked. Its exit status determines the success
184or failure of the update.
185
186This hook executes once for the receive operation. It takes no
187arguments, but for each ref to be updated it receives on standard
188input a line of the format:
189
190 <old-value> SP <new-value> SP <ref-name> LF
191
192where `<old-value>` is the old object name stored in the ref,
193`<new-value>` is the new object name to be stored in the ref and
194`<ref-name>` is the full name of the ref.
195When creating a new ref, `<old-value>` is 40 `0`.
196
197If the hook exits with non-zero status, none of the refs will be
198updated. If the hook exits with zero, updating of individual refs can
199still be prevented by the <<update,'update'>> hook.
200
Junio C Hamano323e52d2007-05-13 22:19:53201Both standard output and standard error output are forwarded to
Junio C Hamanoba4b9282008-07-06 05:20:31202'git-send-pack' on the other end, so you can simply `echo` messages
Junio C Hamano323e52d2007-05-13 22:19:53203for the user.
Junio C Hamano8638c922007-05-12 20:50:08204
205[[update]]
Junio C Hamano1a4e8412005-12-27 08:17:23206update
207------
208
Junio C Hamanoba4b9282008-07-06 05:20:31209This hook is invoked by 'git-receive-pack' on the remote repository,
210which happens when a 'git-push' is done on a local repository.
Junio C Hamano818f7d62006-03-26 01:49:30211Just before updating the ref on the remote repository, the update hook
Junio C Hamano33db4372006-06-07 19:51:45212is invoked. Its exit status determines the success or failure of
Junio C Hamano818f7d62006-03-26 01:49:30213the ref update.
Junio C Hamano1a4e8412005-12-27 08:17:23214
Junio C Hamano818f7d62006-03-26 01:49:30215The hook executes once for each ref to be updated, and takes
216three parameters:
Junio C Hamanod5784132006-09-20 21:29:27217
218 - the name of the ref being updated,
219 - the old object name stored in the ref,
220 - and the new objectname to be stored in the ref.
Junio C Hamano818f7d62006-03-26 01:49:30221
222A zero exit from the update hook allows the ref to be updated.
Junio C Hamanoba4b9282008-07-06 05:20:31223Exiting with a non-zero status prevents 'git-receive-pack'
Junio C Hamano8638c922007-05-12 20:50:08224from updating that ref.
Junio C Hamano818f7d62006-03-26 01:49:30225
226This hook can be used to prevent 'forced' update on certain refs by
Junio C Hamano1a4e8412005-12-27 08:17:23227making sure that the object name is a commit object that is a
228descendant of the commit object named by the old object name.
Junio C Hamano818f7d62006-03-26 01:49:30229That is, to enforce a "fast forward only" policy.
230
231It could also be used to log the old..new status. However, it
232does not know the entire set of branches, so it would end up
Junio C Hamano8638c922007-05-12 20:50:08233firing one e-mail per ref when used naively, though. The
234<<post-receive,'post-receive'>> hook is more suited to that.
Junio C Hamano818f7d62006-03-26 01:49:30235
Junio C Hamano1a4e8412005-12-27 08:17:23236Another use suggested on the mailing list is to use this hook to
237implement access control which is finer grained than the one
238based on filesystem group.
239
Junio C Hamano323e52d2007-05-13 22:19:53240Both standard output and standard error output are forwarded to
Junio C Hamanoba4b9282008-07-06 05:20:31241'git-send-pack' on the other end, so you can simply `echo` messages
Junio C Hamano323e52d2007-05-13 22:19:53242for the user.
Junio C Hamano1a4e8412005-12-27 08:17:23243
Junio C Hamano8638c922007-05-12 20:50:08244The default 'update' hook, when enabled--and with
245`hooks.allowunannotated` config option turned on--prevents
246unannotated tags to be pushed.
Junio C Hamano818f7d62006-03-26 01:49:30247
Junio C Hamano8638c922007-05-12 20:50:08248[[post-receive]]
249post-receive
250------------
251
Junio C Hamanoba4b9282008-07-06 05:20:31252This hook is invoked by 'git-receive-pack' on the remote repository,
253which happens when a 'git-push' is done on a local repository.
Junio C Hamano8638c922007-05-12 20:50:08254It executes on the remote repository once after all the refs have
255been updated.
256
257This hook executes once for the receive operation. It takes no
Junio C Hamano323e52d2007-05-13 22:19:53258arguments, but gets the same information as the
259<<pre-receive,'pre-receive'>>
Junio C Hamano8638c922007-05-12 20:50:08260hook does on its standard input.
261
Junio C Hamanoba4b9282008-07-06 05:20:31262This hook does not affect the outcome of 'git-receive-pack', as it
Junio C Hamano8638c922007-05-12 20:50:08263is called after the real work is done.
264
Junio C Hamanoa6387422007-08-25 03:54:27265This supersedes the <<post-update,'post-update'>> hook in that it gets
Junio C Hamano323e52d2007-05-13 22:19:53266both old and new values of all the refs in addition to their
267names.
Junio C Hamano8638c922007-05-12 20:50:08268
Junio C Hamano323e52d2007-05-13 22:19:53269Both standard output and standard error output are forwarded to
Junio C Hamanoba4b9282008-07-06 05:20:31270'git-send-pack' on the other end, so you can simply `echo` messages
Junio C Hamano323e52d2007-05-13 22:19:53271for the user.
Junio C Hamano8638c922007-05-12 20:50:08272
273The default 'post-receive' hook is empty, but there is
274a sample script `post-receive-email` provided in the `contrib/hooks`
275directory in git distribution, which implements sending commit
276emails.
277
278[[post-update]]
Junio C Hamano1a4e8412005-12-27 08:17:23279post-update
280-----------
281
Junio C Hamanoba4b9282008-07-06 05:20:31282This hook is invoked by 'git-receive-pack' on the remote repository,
283which happens when a 'git-push' is done on a local repository.
Junio C Hamano818f7d62006-03-26 01:49:30284It executes on the remote repository once after all the refs have
285been updated.
286
287It takes a variable number of parameters, each of which is the
288name of ref that was actually updated.
Junio C Hamano1a4e8412005-12-27 08:17:23289
290This hook is meant primarily for notification, and cannot affect
Junio C Hamanoba4b9282008-07-06 05:20:31291the outcome of 'git-receive-pack'.
Junio C Hamano1a4e8412005-12-27 08:17:23292
Junio C Hamanod5784132006-09-20 21:29:27293The 'post-update' hook can tell what are the heads that were pushed,
Junio C Hamano818f7d62006-03-26 01:49:30294but it does not know what their original and updated values are,
Junio C Hamano323e52d2007-05-13 22:19:53295so it is a poor place to do log old..new. The
296<<post-receive,'post-receive'>> hook does get both original and
297updated values of the refs. You might consider it instead if you need
298them.
Junio C Hamano8638c922007-05-12 20:50:08299
Junio C Hamanod5784132006-09-20 21:29:27300When enabled, the default 'post-update' hook runs
Junio C Hamanoba4b9282008-07-06 05:20:31301'git-update-server-info' to keep the information used by dumb
Junio C Hamanod5784132006-09-20 21:29:27302transports (e.g., HTTP) up-to-date. If you are publishing
303a git repository that is accessible via HTTP, you should
Junio C Hamano818f7d62006-03-26 01:49:30304probably enable this hook.
Junio C Hamano1a4e8412005-12-27 08:17:23305
Junio C Hamano8638c922007-05-12 20:50:08306Both standard output and standard error output are forwarded to
Junio C Hamanoba4b9282008-07-06 05:20:31307'git-send-pack' on the other end, so you can simply `echo` messages
Junio C Hamano323e52d2007-05-13 22:19:53308for the user.
Junio C Hamanoe3ddb5b2008-04-21 00:48:07309
310pre-auto-gc
311-----------
312
Junio C Hamanoba4b9282008-07-06 05:20:31313This hook is invoked by 'git-gc --auto'. It takes no parameter, and
314exiting with non-zero status from this script causes the 'git-gc --auto'
Junio C Hamanoe3ddb5b2008-04-21 00:48:07315to abort.
Junio C Hamano2fbcd212008-05-14 22:26:07316
317GIT
318---
Junio C Hamanof7c042d2008-06-06 22:50:53319Part of the linkgit:git[1] suite