blob: 8181e4ed2ad815e5cdc3fe840c9bcdad33ffdd2d [file] [log] [blame]
Junio C Hamano2fbcd212008-05-14 22:26:071githooks(5)
2===========
3
4NAME
5----
Junio C Hamano076ffcc2013-02-06 05:13:216githooks - Hooks used by Git
Junio C Hamano2fbcd212008-05-14 22:26:077
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 Hamano1aa40d22010-01-21 17:46:4318'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
Junio C Hamanoc28068f2009-09-08 00:55:2329HOOKS
30-----
31
Junio C Hamano1a4e8412005-12-27 08:17:2332applypatch-msg
Junio C Hamanoc28068f2009-09-08 00:55:2333~~~~~~~~~~~~~~
Junio C Hamano1a4e8412005-12-27 08:17:2334
Junio C Hamano1aa40d22010-01-21 17:46:4335This hook is invoked by 'git am' script. It takes a single
Junio C Hamano1a4e8412005-12-27 08:17:2336parameter, the name of the file that holds the proposed commit
Junio C Hamanod5784132006-09-20 21:29:2737log message. Exiting with non-zero status causes
Junio C Hamano1aa40d22010-01-21 17:46:4338'git am' to abort before applying the patch.
Junio C Hamano1a4e8412005-12-27 08:17:2339
40The hook is allowed to edit the message file in place, and can
41be used to normalize the message into some project standard
42format (if the project has one). It can also be used to refuse
43the commit after inspecting the message file.
44
Junio C Hamanod5784132006-09-20 21:29:2745The default 'applypatch-msg' hook, when enabled, runs the
46'commit-msg' hook, if the latter is enabled.
Junio C Hamano1a4e8412005-12-27 08:17:2347
48pre-applypatch
Junio C Hamanoc28068f2009-09-08 00:55:2349~~~~~~~~~~~~~~
Junio C Hamano1a4e8412005-12-27 08:17:2350
Junio C Hamano1aa40d22010-01-21 17:46:4351This hook is invoked by 'git am'. It takes no parameter, and is
Junio C Hamanoa31092a2008-05-04 06:41:2352invoked after the patch is applied, but before a commit is made.
53
54If it exits with non-zero status, then the working tree will not be
55committed after applying the patch.
Junio C Hamano1a4e8412005-12-27 08:17:2356
57It can be used to inspect the current working tree and refuse to
58make a commit if it does not pass certain test.
59
Junio C Hamanod5784132006-09-20 21:29:2760The default 'pre-applypatch' hook, when enabled, runs the
61'pre-commit' hook, if the latter is enabled.
Junio C Hamano1a4e8412005-12-27 08:17:2362
63post-applypatch
Junio C Hamanoc28068f2009-09-08 00:55:2364~~~~~~~~~~~~~~~
Junio C Hamano1a4e8412005-12-27 08:17:2365
Junio C Hamano1aa40d22010-01-21 17:46:4366This hook is invoked by 'git am'. It takes no parameter,
Junio C Hamano1a4e8412005-12-27 08:17:2367and is invoked after the patch is applied and a commit is made.
68
69This hook is meant primarily for notification, and cannot affect
Junio C Hamano1aa40d22010-01-21 17:46:4370the outcome of 'git am'.
Junio C Hamano1a4e8412005-12-27 08:17:2371
72pre-commit
Junio C Hamanoc28068f2009-09-08 00:55:2373~~~~~~~~~~
Junio C Hamano1a4e8412005-12-27 08:17:2374
Junio C Hamano1aa40d22010-01-21 17:46:4375This hook is invoked by 'git commit', and can be bypassed
Junio C Hamanob76a6862012-05-02 22:02:4676with `--no-verify` option. It takes no parameter, and is
Junio C Hamano1a4e8412005-12-27 08:17:2377invoked before obtaining the proposed commit log message and
78making a commit. Exiting with non-zero status from this script
Junio C Hamano1aa40d22010-01-21 17:46:4379causes the 'git commit' to abort.
Junio C Hamano1a4e8412005-12-27 08:17:2380
Junio C Hamanod5784132006-09-20 21:29:2781The default 'pre-commit' hook, when enabled, catches introduction
Junio C Hamano1a4e8412005-12-27 08:17:2382of lines with trailing whitespaces and aborts the commit when
Junio C Hamanod5784132006-09-20 21:29:2783such a line is found.
Junio C Hamano1a4e8412005-12-27 08:17:2384
Junio C Hamano1aa40d22010-01-21 17:46:4385All the 'git commit' hooks are invoked with the environment
Junio C Hamano26e590a2008-02-17 03:53:5186variable `GIT_EDITOR=:` if the command will not bring up an editor
87to modify the commit message.
88
89prepare-commit-msg
Junio C Hamanoc28068f2009-09-08 00:55:2390~~~~~~~~~~~~~~~~~~
Junio C Hamano26e590a2008-02-17 03:53:5191
Junio C Hamano1aa40d22010-01-21 17:46:4392This hook is invoked by 'git commit' right after preparing the
Junio C Hamano26e590a2008-02-17 03:53:5193default log message, and before the editor is started.
94
95It takes one to three parameters. The first is the name of the file
Junio C Hamanobd53dbf2009-01-18 18:26:3796that contains the commit log message. The second is the source of the commit
Junio C Hamanoa476efa2008-10-10 15:31:4297message, and can be: `message` (if a `-m` or `-F` option was
98given); `template` (if a `-t` option was given or the
Junio C Hamano26e590a2008-02-17 03:53:5199configuration option `commit.template` is set); `merge` (if the
100commit is a merge or a `.git/MERGE_MSG` file exists); `squash`
101(if a `.git/SQUASH_MSG` file exists); or `commit`, followed by
Junio C Hamanob76a6862012-05-02 22:02:46102a commit SHA1 (if a `-c`, `-C` or `--amend` option was given).
Junio C Hamano26e590a2008-02-17 03:53:51103
Junio C Hamano1aa40d22010-01-21 17:46:43104If the exit status is non-zero, 'git commit' will abort.
Junio C Hamano26e590a2008-02-17 03:53:51105
106The purpose of the hook is to edit the message file in place, and
Junio C Hamanob76a6862012-05-02 22:02:46107it is not suppressed by the `--no-verify` option. A non-zero exit
Junio C Hamano26e590a2008-02-17 03:53:51108means a failure of the hook and aborts the commit. It should not
109be used as replacement for pre-commit hook.
110
Junio C Hamano076ffcc2013-02-06 05:13:21111The sample `prepare-commit-msg` hook that comes with Git comments
Junio C Hamano26e590a2008-02-17 03:53:51112out the `Conflicts:` part of a merge's commit message.
113
Junio C Hamano1a4e8412005-12-27 08:17:23114commit-msg
Junio C Hamanoc28068f2009-09-08 00:55:23115~~~~~~~~~~
Junio C Hamano1a4e8412005-12-27 08:17:23116
Junio C Hamano1aa40d22010-01-21 17:46:43117This hook is invoked by 'git commit', and can be bypassed
Junio C Hamanob76a6862012-05-02 22:02:46118with `--no-verify` option. It takes a single parameter, the
Junio C Hamano1a4e8412005-12-27 08:17:23119name of the file that holds the proposed commit log message.
Junio C Hamano1aa40d22010-01-21 17:46:43120Exiting with non-zero status causes the 'git commit' to
Junio C Hamano1a4e8412005-12-27 08:17:23121abort.
122
123The hook is allowed to edit the message file in place, and can
124be used to normalize the message into some project standard
125format (if the project has one). It can also be used to refuse
126the commit after inspecting the message file.
127
Junio C Hamanod5784132006-09-20 21:29:27128The default 'commit-msg' hook, when enabled, detects duplicate
129"Signed-off-by" lines, and aborts the commit if one is found.
Junio C Hamano1a4e8412005-12-27 08:17:23130
131post-commit
Junio C Hamanoc28068f2009-09-08 00:55:23132~~~~~~~~~~~
Junio C Hamano1a4e8412005-12-27 08:17:23133
Junio C Hamano1aa40d22010-01-21 17:46:43134This hook is invoked by 'git commit'. It takes no
Junio C Hamano1a4e8412005-12-27 08:17:23135parameter, and is invoked after a commit is made.
136
137This hook is meant primarily for notification, and cannot affect
Junio C Hamano1aa40d22010-01-21 17:46:43138the outcome of 'git commit'.
Junio C Hamano1a4e8412005-12-27 08:17:23139
Junio C Hamanoa476efa2008-10-10 15:31:42140pre-rebase
Junio C Hamanoc28068f2009-09-08 00:55:23141~~~~~~~~~~
Junio C Hamanoa476efa2008-10-10 15:31:42142
Junio C Hamano1aa40d22010-01-21 17:46:43143This hook is called by 'git rebase' and can be used to prevent a branch
Junio C Hamanoa476efa2008-10-10 15:31:42144from getting rebased.
145
146
Junio C Hamano1b50ce92007-10-03 12:05:53147post-checkout
Junio C Hamanoc28068f2009-09-08 00:55:23148~~~~~~~~~~~~~
Junio C Hamano1b50ce92007-10-03 12:05:53149
Junio C Hamano1aa40d22010-01-21 17:46:43150This hook is invoked when a 'git checkout' is run after having updated the
Junio C Hamano1b50ce92007-10-03 12:05:53151worktree. The hook is given three parameters: the ref of the previous HEAD,
152the ref of the new HEAD (which may or may not have changed), and a flag
153indicating whether the checkout was a branch checkout (changing branches,
154flag=1) or a file checkout (retrieving a file from the index, flag=0).
Junio C Hamano1aa40d22010-01-21 17:46:43155This hook cannot affect the outcome of 'git checkout'.
Junio C Hamano1b50ce92007-10-03 12:05:53156
Junio C Hamano1aa40d22010-01-21 17:46:43157It is also run after 'git clone', unless the --no-checkout (-n) option is
Junio C Hamano36a56722009-03-28 08:55:34158used. The first parameter given to the hook is the null-ref, the second the
159ref of the new HEAD and the flag is always 1.
160
Junio C Hamano1b50ce92007-10-03 12:05:53161This hook can be used to perform repository validity checks, auto-display
162differences from the previous HEAD if different, or set working dir metadata
163properties.
164
Junio C Hamano01d8f832007-09-24 07:37:30165post-merge
Junio C Hamanoc28068f2009-09-08 00:55:23166~~~~~~~~~~
Junio C Hamano01d8f832007-09-24 07:37:30167
Junio C Hamano1aa40d22010-01-21 17:46:43168This hook is invoked by 'git merge', which happens when a 'git pull'
Junio C Hamano01d8f832007-09-24 07:37:30169is done on a local repository. The hook takes a single parameter, a status
170flag specifying whether or not the merge being done was a squash merge.
Junio C Hamano1aa40d22010-01-21 17:46:43171This hook cannot affect the outcome of 'git merge' and is not executed,
Junio C Hamano47d68a52008-05-06 06:35:40172if the merge failed due to conflicts.
Junio C Hamano01d8f832007-09-24 07:37:30173
174This hook can be used in conjunction with a corresponding pre-commit hook to
175save and restore any form of metadata associated with the working tree
176(eg: permissions/ownership, ACLS, etc). See contrib/hooks/setgitperms.perl
177for an example of how to do this.
178
Junio C Hamano36d52292013-01-25 21:32:36179pre-push
180~~~~~~~~
181
182This hook is called by 'git push' and can be used to prevent a push from taking
183place. The hook is called with two parameters which provide the name and
184location of the destination remote, if a named remote is not being used both
185values will be the same.
186
187Information about what is to be pushed is provided on the hook's standard
188input with lines of the form:
189
190 <local ref> SP <local sha1> SP <remote ref> SP <remote sha1> LF
191
192For instance, if the command +git push origin master:foreign+ were run the
193hook would receive a line like the following:
194
195 refs/heads/master 67890 refs/heads/foreign 12345
196
197although the full, 40-character SHA1s would be supplied. If the foreign ref
198does not yet exist the `<remote SHA1>` will be 40 `0`. If a ref is to be
199deleted, the `<local ref>` will be supplied as `(delete)` and the `<local
200SHA1>` will be 40 `0`. If the local commit was specified by something other
201than a name which could be expanded (such as `HEAD~`, or a SHA1) it will be
202supplied as it was originally given.
203
204If this hook exits with a non-zero status, 'git push' will abort without
205pushing anything. Information about why the push is rejected may be sent
206to the user by writing to standard error.
207
Junio C Hamano8638c922007-05-12 20:50:08208[[pre-receive]]
209pre-receive
Junio C Hamanoc28068f2009-09-08 00:55:23210~~~~~~~~~~~
Junio C Hamano8638c922007-05-12 20:50:08211
Junio C Hamanoba4b9282008-07-06 05:20:31212This hook is invoked by 'git-receive-pack' on the remote repository,
Junio C Hamano1aa40d22010-01-21 17:46:43213which happens when a 'git push' is done on a local repository.
Junio C Hamano8638c922007-05-12 20:50:08214Just before starting to update refs on the remote repository, the
215pre-receive hook is invoked. Its exit status determines the success
216or failure of the update.
217
218This hook executes once for the receive operation. It takes no
219arguments, but for each ref to be updated it receives on standard
220input a line of the format:
221
222 <old-value> SP <new-value> SP <ref-name> LF
223
224where `<old-value>` is the old object name stored in the ref,
225`<new-value>` is the new object name to be stored in the ref and
226`<ref-name>` is the full name of the ref.
227When creating a new ref, `<old-value>` is 40 `0`.
228
229If the hook exits with non-zero status, none of the refs will be
230updated. If the hook exits with zero, updating of individual refs can
231still be prevented by the <<update,'update'>> hook.
232
Junio C Hamano323e52d2007-05-13 22:19:53233Both standard output and standard error output are forwarded to
Junio C Hamano1aa40d22010-01-21 17:46:43234'git send-pack' on the other end, so you can simply `echo` messages
Junio C Hamano323e52d2007-05-13 22:19:53235for the user.
Junio C Hamano8638c922007-05-12 20:50:08236
237[[update]]
Junio C Hamano1a4e8412005-12-27 08:17:23238update
Junio C Hamanoc28068f2009-09-08 00:55:23239~~~~~~
Junio C Hamano1a4e8412005-12-27 08:17:23240
Junio C Hamanoba4b9282008-07-06 05:20:31241This hook is invoked by 'git-receive-pack' on the remote repository,
Junio C Hamano1aa40d22010-01-21 17:46:43242which happens when a 'git push' is done on a local repository.
Junio C Hamano818f7d62006-03-26 01:49:30243Just before updating the ref on the remote repository, the update hook
Junio C Hamano33db4372006-06-07 19:51:45244is invoked. Its exit status determines the success or failure of
Junio C Hamano818f7d62006-03-26 01:49:30245the ref update.
Junio C Hamano1a4e8412005-12-27 08:17:23246
Junio C Hamano818f7d62006-03-26 01:49:30247The hook executes once for each ref to be updated, and takes
248three parameters:
Junio C Hamanod5784132006-09-20 21:29:27249
250 - the name of the ref being updated,
251 - the old object name stored in the ref,
252 - and the new objectname to be stored in the ref.
Junio C Hamano818f7d62006-03-26 01:49:30253
254A zero exit from the update hook allows the ref to be updated.
Junio C Hamanoba4b9282008-07-06 05:20:31255Exiting with a non-zero status prevents 'git-receive-pack'
Junio C Hamano8638c922007-05-12 20:50:08256from updating that ref.
Junio C Hamano818f7d62006-03-26 01:49:30257
258This hook can be used to prevent 'forced' update on certain refs by
Junio C Hamano1a4e8412005-12-27 08:17:23259making sure that the object name is a commit object that is a
260descendant of the commit object named by the old object name.
Junio C Hamano3f680f32009-11-16 02:10:54261That is, to enforce a "fast-forward only" policy.
Junio C Hamano818f7d62006-03-26 01:49:30262
263It could also be used to log the old..new status. However, it
264does not know the entire set of branches, so it would end up
Junio C Hamano8638c922007-05-12 20:50:08265firing one e-mail per ref when used naively, though. The
266<<post-receive,'post-receive'>> hook is more suited to that.
Junio C Hamano818f7d62006-03-26 01:49:30267
Junio C Hamano1a4e8412005-12-27 08:17:23268Another use suggested on the mailing list is to use this hook to
269implement access control which is finer grained than the one
270based on filesystem group.
271
Junio C Hamano323e52d2007-05-13 22:19:53272Both standard output and standard error output are forwarded to
Junio C Hamano1aa40d22010-01-21 17:46:43273'git send-pack' on the other end, so you can simply `echo` messages
Junio C Hamano323e52d2007-05-13 22:19:53274for the user.
Junio C Hamano1a4e8412005-12-27 08:17:23275
Junio C Hamano8638c922007-05-12 20:50:08276The default 'update' hook, when enabled--and with
Junio C Hamanod6fff402009-09-14 09:40:50277`hooks.allowunannotated` config option unset or set to false--prevents
Junio C Hamano8638c922007-05-12 20:50:08278unannotated tags to be pushed.
Junio C Hamano818f7d62006-03-26 01:49:30279
Junio C Hamano8638c922007-05-12 20:50:08280[[post-receive]]
281post-receive
Junio C Hamanoc28068f2009-09-08 00:55:23282~~~~~~~~~~~~
Junio C Hamano8638c922007-05-12 20:50:08283
Junio C Hamanoba4b9282008-07-06 05:20:31284This hook is invoked by 'git-receive-pack' on the remote repository,
Junio C Hamano1aa40d22010-01-21 17:46:43285which happens when a 'git push' is done on a local repository.
Junio C Hamano8638c922007-05-12 20:50:08286It executes on the remote repository once after all the refs have
287been updated.
288
289This hook executes once for the receive operation. It takes no
Junio C Hamano323e52d2007-05-13 22:19:53290arguments, but gets the same information as the
291<<pre-receive,'pre-receive'>>
Junio C Hamano8638c922007-05-12 20:50:08292hook does on its standard input.
293
Junio C Hamanoba4b9282008-07-06 05:20:31294This hook does not affect the outcome of 'git-receive-pack', as it
Junio C Hamano8638c922007-05-12 20:50:08295is called after the real work is done.
296
Junio C Hamanoa6387422007-08-25 03:54:27297This supersedes the <<post-update,'post-update'>> hook in that it gets
Junio C Hamano323e52d2007-05-13 22:19:53298both old and new values of all the refs in addition to their
299names.
Junio C Hamano8638c922007-05-12 20:50:08300
Junio C Hamano323e52d2007-05-13 22:19:53301Both standard output and standard error output are forwarded to
Junio C Hamano1aa40d22010-01-21 17:46:43302'git send-pack' on the other end, so you can simply `echo` messages
Junio C Hamano323e52d2007-05-13 22:19:53303for the user.
Junio C Hamano8638c922007-05-12 20:50:08304
305The default 'post-receive' hook is empty, but there is
306a sample script `post-receive-email` provided in the `contrib/hooks`
Junio C Hamano076ffcc2013-02-06 05:13:21307directory in Git distribution, which implements sending commit
Junio C Hamano8638c922007-05-12 20:50:08308emails.
309
310[[post-update]]
Junio C Hamano1a4e8412005-12-27 08:17:23311post-update
Junio C Hamanoc28068f2009-09-08 00:55:23312~~~~~~~~~~~
Junio C Hamano1a4e8412005-12-27 08:17:23313
Junio C Hamanoba4b9282008-07-06 05:20:31314This hook is invoked by 'git-receive-pack' on the remote repository,
Junio C Hamano1aa40d22010-01-21 17:46:43315which happens when a 'git push' is done on a local repository.
Junio C Hamano818f7d62006-03-26 01:49:30316It executes on the remote repository once after all the refs have
317been updated.
318
319It takes a variable number of parameters, each of which is the
320name of ref that was actually updated.
Junio C Hamano1a4e8412005-12-27 08:17:23321
322This hook is meant primarily for notification, and cannot affect
Junio C Hamanoba4b9282008-07-06 05:20:31323the outcome of 'git-receive-pack'.
Junio C Hamano1a4e8412005-12-27 08:17:23324
Junio C Hamanod5784132006-09-20 21:29:27325The 'post-update' hook can tell what are the heads that were pushed,
Junio C Hamano818f7d62006-03-26 01:49:30326but it does not know what their original and updated values are,
Junio C Hamano323e52d2007-05-13 22:19:53327so it is a poor place to do log old..new. The
328<<post-receive,'post-receive'>> hook does get both original and
329updated values of the refs. You might consider it instead if you need
330them.
Junio C Hamano8638c922007-05-12 20:50:08331
Junio C Hamanod5784132006-09-20 21:29:27332When enabled, the default 'post-update' hook runs
Junio C Hamano1aa40d22010-01-21 17:46:43333'git update-server-info' to keep the information used by dumb
Junio C Hamanod5784132006-09-20 21:29:27334transports (e.g., HTTP) up-to-date. If you are publishing
Junio C Hamano076ffcc2013-02-06 05:13:21335a Git repository that is accessible via HTTP, you should
Junio C Hamano818f7d62006-03-26 01:49:30336probably enable this hook.
Junio C Hamano1a4e8412005-12-27 08:17:23337
Junio C Hamano8638c922007-05-12 20:50:08338Both standard output and standard error output are forwarded to
Junio C Hamano1aa40d22010-01-21 17:46:43339'git send-pack' on the other end, so you can simply `echo` messages
Junio C Hamano323e52d2007-05-13 22:19:53340for the user.
Junio C Hamanoe3ddb5b2008-04-21 00:48:07341
342pre-auto-gc
Junio C Hamanoc28068f2009-09-08 00:55:23343~~~~~~~~~~~
Junio C Hamanoe3ddb5b2008-04-21 00:48:07344
Junio C Hamano1aa40d22010-01-21 17:46:43345This hook is invoked by 'git gc --auto'. It takes no parameter, and
346exiting with non-zero status from this script causes the 'git gc --auto'
Junio C Hamanoe3ddb5b2008-04-21 00:48:07347to abort.
Junio C Hamano2fbcd212008-05-14 22:26:07348
Junio C Hamano31667362010-03-25 00:38:53349post-rewrite
350~~~~~~~~~~~~
351
352This hook is invoked by commands that rewrite commits (`git commit
353--amend`, 'git-rebase'; currently 'git-filter-branch' does 'not' call
354it!). Its first argument denotes the command it was invoked by:
355currently one of `amend` or `rebase`. Further command-dependent
356arguments may be passed in the future.
357
358The hook receives a list of the rewritten commits on stdin, in the
359format
360
361 <old-sha1> SP <new-sha1> [ SP <extra-info> ] LF
362
363The 'extra-info' is again command-dependent. If it is empty, the
364preceding SP is also omitted. Currently, no commands pass any
365'extra-info'.
366
367The hook always runs after the automatic note copying (see
368"notes.rewrite.<command>" in linkgit:git-config.txt) has happened, and
369thus has access to these notes.
370
371The following command-specific comments apply:
372
373rebase::
374For the 'squash' and 'fixup' operation, all commits that were
375squashed are listed as being rewritten to the squashed commit.
376This means that there will be several lines sharing the same
377'new-sha1'.
378+
379The commits are guaranteed to be listed in the order that they were
380processed by rebase.
381
Junio C Hamano31667362010-03-25 00:38:53382
Junio C Hamano2fbcd212008-05-14 22:26:07383GIT
384---
Junio C Hamanof7c042d2008-06-06 22:50:53385Part of the linkgit:git[1] suite