blob: 86f804720ae71fc3d0db94623663539bd05a06f2 [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--------
Junio C Hamano198b1f12016-05-17 22:27:2410$GIT_DIR/hooks/* (or \`git config core.hooksPath`/*)
Junio C Hamano2fbcd212008-05-14 22:26:0711
12
13DESCRIPTION
14-----------
Junio C Hamano1a4e8412005-12-27 08:17:2315
Junio C Hamano198b1f12016-05-17 22:27:2416Hooks 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.
Junio C Hamano1a4e8412005-12-27 08:17:2319
Junio C Hamano198b1f12016-05-17 22:27:2420By default the hooks directory is `$GIT_DIR/hooks`, but that can be
21changed via the `core.hooksPath` configuration variable (see
22linkgit:git-config[1]).
Junio C Hamano8a48fa22008-12-18 08:44:3023
Junio C Hamano198b1f12016-05-17 22:27:2424Before Git invokes a hook, it changes its working directory to either
Junio C Hamano4c60d9a2017-05-04 14:36:2225$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.
Junio C Hamano198b1f12016-05-17 22:27:2429
Junio C Hamanoa75aada2023-01-22 01:54:3030Environment variables, such as `GIT_DIR`, `GIT_WORK_TREE`, etc., are exported
31so that Git commands run by the hook can correctly locate the repository. If
32your hook needs to invoke Git commands in a foreign repository or in a
33different working tree of the same repository, then it should clear these
34environment variables so they do not interfere with Git operations at the
35foreign location. For example:
36
37------------
38local_desc=$(git describe)
39foreign_desc=$(unset $(git rev-parse --local-env-vars); git -C ../foreign-repo describe)
40------------
41
Junio C Hamano198b1f12016-05-17 22:27:2442Hooks can get their arguments via the environment, command-line
43arguments, and stdin. See the documentation for each hook below for
44details.
45
Junio C Hamanob9d9d902018-05-23 07:07:4246`git init` may copy hooks to the new repository, depending on its
Junio C Hamano198b1f12016-05-17 22:27:2447configuration. See the "TEMPLATE DIRECTORY" section in
48linkgit:git-init[1] for details. When the rest of this document refers
49to "default hooks" it's talking about the default template shipped
50with Git.
51
52The currently supported hooks are described below.
Junio C Hamano1a4e8412005-12-27 08:17:2353
Junio C Hamanoc28068f2009-09-08 00:55:2354HOOKS
55-----
56
Junio C Hamano1a4e8412005-12-27 08:17:2357applypatch-msg
Junio C Hamanoc28068f2009-09-08 00:55:2358~~~~~~~~~~~~~~
Junio C Hamano1a4e8412005-12-27 08:17:2359
Junio C Hamanob9d9d902018-05-23 07:07:4260This hook is invoked by linkgit:git-am[1]. It takes a single
Junio C Hamano1a4e8412005-12-27 08:17:2361parameter, the name of the file that holds the proposed commit
Junio C Hamanob9d9d902018-05-23 07:07:4262log message. Exiting with a non-zero status causes `git am` to abort
Junio C Hamano198b1f12016-05-17 22:27:2463before applying the patch.
Junio C Hamano1a4e8412005-12-27 08:17:2364
65The hook is allowed to edit the message file in place, and can
66be used to normalize the message into some project standard
Junio C Hamano198b1f12016-05-17 22:27:2467format. It can also be used to refuse the commit after inspecting
68the message file.
Junio C Hamano1a4e8412005-12-27 08:17:2369
Junio C Hamanod5784132006-09-20 21:29:2770The default 'applypatch-msg' hook, when enabled, runs the
71'commit-msg' hook, if the latter is enabled.
Junio C Hamano1a4e8412005-12-27 08:17:2372
73pre-applypatch
Junio C Hamanoc28068f2009-09-08 00:55:2374~~~~~~~~~~~~~~
Junio C Hamano1a4e8412005-12-27 08:17:2375
Junio C Hamanob9d9d902018-05-23 07:07:4276This hook is invoked by linkgit:git-am[1]. It takes no parameter, and is
Junio C Hamanoa31092a2008-05-04 06:41:2377invoked after the patch is applied, but before a commit is made.
78
79If it exits with non-zero status, then the working tree will not be
80committed after applying the patch.
Junio C Hamano1a4e8412005-12-27 08:17:2381
82It can be used to inspect the current working tree and refuse to
83make a commit if it does not pass certain test.
84
Junio C Hamanod5784132006-09-20 21:29:2785The default 'pre-applypatch' hook, when enabled, runs the
86'pre-commit' hook, if the latter is enabled.
Junio C Hamano1a4e8412005-12-27 08:17:2387
88post-applypatch
Junio C Hamanoc28068f2009-09-08 00:55:2389~~~~~~~~~~~~~~~
Junio C Hamano1a4e8412005-12-27 08:17:2390
Junio C Hamanob9d9d902018-05-23 07:07:4291This hook is invoked by linkgit:git-am[1]. It takes no parameter,
Junio C Hamano1a4e8412005-12-27 08:17:2392and is invoked after the patch is applied and a commit is made.
93
94This hook is meant primarily for notification, and cannot affect
Junio C Hamanob9d9d902018-05-23 07:07:4295the outcome of `git am`.
Junio C Hamano1a4e8412005-12-27 08:17:2396
97pre-commit
Junio C Hamanoc28068f2009-09-08 00:55:2398~~~~~~~~~~
Junio C Hamano1a4e8412005-12-27 08:17:2399
Junio C Hamanob9d9d902018-05-23 07:07:42100This hook is invoked by linkgit:git-commit[1], and can be bypassed
Junio C Hamano198b1f12016-05-17 22:27:24101with the `--no-verify` option. It takes no parameters, and is
Junio C Hamano1a4e8412005-12-27 08:17:23102invoked before obtaining the proposed commit log message and
Junio C Hamano198b1f12016-05-17 22:27:24103making a commit. Exiting with a non-zero status from this script
Junio C Hamanob9d9d902018-05-23 07:07:42104causes the `git commit` command to abort before creating a commit.
Junio C Hamano1a4e8412005-12-27 08:17:23105
Junio C Hamanod5784132006-09-20 21:29:27106The default 'pre-commit' hook, when enabled, catches introduction
Junio C Hamano1a4e8412005-12-27 08:17:23107of lines with trailing whitespaces and aborts the commit when
Junio C Hamanod5784132006-09-20 21:29:27108such a line is found.
Junio C Hamano1a4e8412005-12-27 08:17:23109
Junio C Hamanob9d9d902018-05-23 07:07:42110All the `git commit` hooks are invoked with the environment
Junio C Hamano26e590a2008-02-17 03:53:51111variable `GIT_EDITOR=:` if the command will not bring up an editor
112to modify the commit message.
113
Junio C Hamano11f15372019-03-07 03:17:00114The default 'pre-commit' hook, when enabled--and with the
115`hooks.allownonascii` config option unset or set to false--prevents
116the use of non-ASCII filenames.
117
Junio C Hamanocb705392019-09-18 19:30:01118pre-merge-commit
119~~~~~~~~~~~~~~~~
120
121This hook is invoked by linkgit:git-merge[1], and can be bypassed
122with the `--no-verify` option. It takes no parameters, and is
123invoked after the merge has been carried out successfully and before
124obtaining the proposed commit log message to
125make a commit. Exiting with a non-zero status from this script
126causes the `git merge` command to abort before creating a commit.
127
128The default 'pre-merge-commit' hook, when enabled, runs the
129'pre-commit' hook, if the latter is enabled.
130
131This hook is invoked with the environment variable
132`GIT_EDITOR=:` if the command will not bring up an editor
133to modify the commit message.
134
135If the merge cannot be carried out automatically, the conflicts
136need to be resolved and the result committed separately (see
137linkgit:git-merge[1]). At that point, this hook will not be executed,
138but the 'pre-commit' hook will, if it is enabled.
139
Junio C Hamano26e590a2008-02-17 03:53:51140prepare-commit-msg
Junio C Hamanoc28068f2009-09-08 00:55:23141~~~~~~~~~~~~~~~~~~
Junio C Hamano26e590a2008-02-17 03:53:51142
Junio C Hamanob9d9d902018-05-23 07:07:42143This hook is invoked by linkgit:git-commit[1] right after preparing the
Junio C Hamano26e590a2008-02-17 03:53:51144default log message, and before the editor is started.
145
146It takes one to three parameters. The first is the name of the file
Junio C Hamanobd53dbf2009-01-18 18:26:37147that contains the commit log message. The second is the source of the commit
Junio C Hamanoa476efa2008-10-10 15:31:42148message, and can be: `message` (if a `-m` or `-F` option was
149given); `template` (if a `-t` option was given or the
Junio C Hamano26e590a2008-02-17 03:53:51150configuration option `commit.template` is set); `merge` (if the
151commit is a merge or a `.git/MERGE_MSG` file exists); `squash`
152(if a `.git/SQUASH_MSG` file exists); or `commit`, followed by
Junio C Hamano458281a2021-03-22 21:20:26153a commit object name (if a `-c`, `-C` or `--amend` option was given).
Junio C Hamano26e590a2008-02-17 03:53:51154
Junio C Hamanob9d9d902018-05-23 07:07:42155If the exit status is non-zero, `git commit` will abort.
Junio C Hamano26e590a2008-02-17 03:53:51156
157The purpose of the hook is to edit the message file in place, and
Junio C Hamanob76a6862012-05-02 22:02:46158it is not suppressed by the `--no-verify` option. A non-zero exit
Junio C Hamano26e590a2008-02-17 03:53:51159means a failure of the hook and aborts the commit. It should not
160be used as replacement for pre-commit hook.
161
Junio C Hamano4b2a6c12017-08-22 18:32:37162The sample `prepare-commit-msg` hook that comes with Git removes the
163help message found in the commented portion of the commit template.
Junio C Hamano26e590a2008-02-17 03:53:51164
Junio C Hamano1a4e8412005-12-27 08:17:23165commit-msg
Junio C Hamanoc28068f2009-09-08 00:55:23166~~~~~~~~~~
Junio C Hamano1a4e8412005-12-27 08:17:23167
Junio C Hamanob9d9d902018-05-23 07:07:42168This hook is invoked by linkgit:git-commit[1] and linkgit:git-merge[1], and can be
Junio C Hamanoef75f372017-09-29 04:22:33169bypassed with the `--no-verify` option. It takes a single parameter,
170the name of the file that holds the proposed commit log message.
171Exiting with a non-zero status causes the command to abort.
Junio C Hamano1a4e8412005-12-27 08:17:23172
Junio C Hamano198b1f12016-05-17 22:27:24173The hook is allowed to edit the message file in place, and can be used
174to normalize the message into some project standard format. It
175can also be used to refuse the commit after inspecting the message
176file.
Junio C Hamano1a4e8412005-12-27 08:17:23177
Junio C Hamanod5784132006-09-20 21:29:27178The default 'commit-msg' hook, when enabled, detects duplicate
Junio C Hamanodf3d3cd2020-11-02 22:05:05179`Signed-off-by` trailers, and aborts the commit if one is found.
Junio C Hamano1a4e8412005-12-27 08:17:23180
181post-commit
Junio C Hamanoc28068f2009-09-08 00:55:23182~~~~~~~~~~~
Junio C Hamano1a4e8412005-12-27 08:17:23183
Junio C Hamanob9d9d902018-05-23 07:07:42184This hook is invoked by linkgit:git-commit[1]. It takes no parameters, and is
Junio C Hamano198b1f12016-05-17 22:27:24185invoked after a commit is made.
Junio C Hamano1a4e8412005-12-27 08:17:23186
187This hook is meant primarily for notification, and cannot affect
Junio C Hamanob9d9d902018-05-23 07:07:42188the outcome of `git commit`.
Junio C Hamano1a4e8412005-12-27 08:17:23189
Junio C Hamanoa476efa2008-10-10 15:31:42190pre-rebase
Junio C Hamanoc28068f2009-09-08 00:55:23191~~~~~~~~~~
Junio C Hamanoa476efa2008-10-10 15:31:42192
Junio C Hamanob9d9d902018-05-23 07:07:42193This hook is called by linkgit:git-rebase[1] and can be used to prevent a
Junio C Hamano947ab822013-03-19 23:07:29194branch from getting rebased. The hook may be called with one or
195two parameters. The first parameter is the upstream from which
196the series was forked. The second parameter is the branch being
197rebased, and is not set when rebasing the current branch.
Junio C Hamanoa476efa2008-10-10 15:31:42198
Junio C Hamano1b50ce92007-10-03 12:05:53199post-checkout
Junio C Hamanoc28068f2009-09-08 00:55:23200~~~~~~~~~~~~~
Junio C Hamano1b50ce92007-10-03 12:05:53201
Junio C Hamanoc9f11c22019-07-10 02:54:04202This hook is invoked when a linkgit:git-checkout[1] or
203linkgit:git-switch[1] is run after having updated the
Junio C Hamano1b50ce92007-10-03 12:05:53204worktree. The hook is given three parameters: the ref of the previous HEAD,
205the ref of the new HEAD (which may or may not have changed), and a flag
206indicating whether the checkout was a branch checkout (changing branches,
207flag=1) or a file checkout (retrieving a file from the index, flag=0).
Junio C Hamano558abd22020-09-03 20:22:34208This hook cannot affect the outcome of `git switch` or `git checkout`,
209other than that the hook's exit status becomes the exit status of
210these two commands.
Junio C Hamano1b50ce92007-10-03 12:05:53211
Junio C Hamanob9d9d902018-05-23 07:07:42212It is also run after linkgit:git-clone[1], unless the `--no-checkout` (`-n`) option is
Junio C Hamano36a56722009-03-28 08:55:34213used. The first parameter given to the hook is the null-ref, the second the
Junio C Hamanob9d9d902018-05-23 07:07:42214ref of the new HEAD and the flag is always 1. Likewise for `git worktree add`
215unless `--no-checkout` is used.
Junio C Hamano36a56722009-03-28 08:55:34216
Junio C Hamano1b50ce92007-10-03 12:05:53217This hook can be used to perform repository validity checks, auto-display
218differences from the previous HEAD if different, or set working dir metadata
219properties.
220
Junio C Hamano01d8f832007-09-24 07:37:30221post-merge
Junio C Hamanoc28068f2009-09-08 00:55:23222~~~~~~~~~~
Junio C Hamano01d8f832007-09-24 07:37:30223
Junio C Hamanob9d9d902018-05-23 07:07:42224This hook is invoked by linkgit:git-merge[1], which happens when a `git pull`
Junio C Hamano01d8f832007-09-24 07:37:30225is done on a local repository. The hook takes a single parameter, a status
226flag specifying whether or not the merge being done was a squash merge.
Junio C Hamanob9d9d902018-05-23 07:07:42227This hook cannot affect the outcome of `git merge` and is not executed,
Junio C Hamano47d68a52008-05-06 06:35:40228if the merge failed due to conflicts.
Junio C Hamano01d8f832007-09-24 07:37:30229
230This hook can be used in conjunction with a corresponding pre-commit hook to
231save and restore any form of metadata associated with the working tree
Junio C Hamanofb5ffde2014-11-04 22:38:56232(e.g.: permissions/ownership, ACLS, etc). See contrib/hooks/setgitperms.perl
Junio C Hamano01d8f832007-09-24 07:37:30233for an example of how to do this.
234
Junio C Hamano36d52292013-01-25 21:32:36235pre-push
236~~~~~~~~
237
Junio C Hamanob9d9d902018-05-23 07:07:42238This hook is called by linkgit:git-push[1] and can be used to prevent
239a push from taking place. The hook is called with two parameters
240which provide the name and location of the destination remote, if a
241named remote is not being used both values will be the same.
Junio C Hamano36d52292013-01-25 21:32:36242
243Information about what is to be pushed is provided on the hook's standard
244input with lines of the form:
245
Junio C Hamano458281a2021-03-22 21:20:26246 <local ref> SP <local object name> SP <remote ref> SP <remote object name> LF
Junio C Hamano36d52292013-01-25 21:32:36247
248For instance, if the command +git push origin master:foreign+ were run the
249hook would receive a line like the following:
250
251 refs/heads/master 67890 refs/heads/foreign 12345
252
Junio C Hamano458281a2021-03-22 21:20:26253although the full object name would be supplied. If the foreign ref does not
254yet exist the `<remote object name>` will be the all-zeroes object name. If a
255ref is to be deleted, the `<local ref>` will be supplied as `(delete)` and the
256`<local object name>` will be the all-zeroes object name. If the local commit
257was specified by something other than a name which could be expanded (such as
258`HEAD~`, or an object name) it will be supplied as it was originally given.
Junio C Hamano36d52292013-01-25 21:32:36259
Junio C Hamanob9d9d902018-05-23 07:07:42260If this hook exits with a non-zero status, `git push` will abort without
Junio C Hamano36d52292013-01-25 21:32:36261pushing anything. Information about why the push is rejected may be sent
262to the user by writing to standard error.
263
Junio C Hamano8638c922007-05-12 20:50:08264[[pre-receive]]
265pre-receive
Junio C Hamanoc28068f2009-09-08 00:55:23266~~~~~~~~~~~
Junio C Hamano8638c922007-05-12 20:50:08267
Junio C Hamanob9d9d902018-05-23 07:07:42268This hook is invoked by linkgit:git-receive-pack[1] when it reacts to
269`git push` and updates reference(s) in its repository.
Junio C Hamano8638c922007-05-12 20:50:08270Just before starting to update refs on the remote repository, the
271pre-receive hook is invoked. Its exit status determines the success
272or failure of the update.
273
274This hook executes once for the receive operation. It takes no
275arguments, but for each ref to be updated it receives on standard
276input a line of the format:
277
278 <old-value> SP <new-value> SP <ref-name> LF
279
280where `<old-value>` is the old object name stored in the ref,
281`<new-value>` is the new object name to be stored in the ref and
282`<ref-name>` is the full name of the ref.
Junio C Hamano458281a2021-03-22 21:20:26283When creating a new ref, `<old-value>` is the all-zeroes object name.
Junio C Hamano8638c922007-05-12 20:50:08284
285If the hook exits with non-zero status, none of the refs will be
286updated. If the hook exits with zero, updating of individual refs can
287still be prevented by the <<update,'update'>> hook.
288
Junio C Hamano323e52d2007-05-13 22:19:53289Both standard output and standard error output are forwarded to
Junio C Hamanob9d9d902018-05-23 07:07:42290`git send-pack` on the other end, so you can simply `echo` messages
Junio C Hamano323e52d2007-05-13 22:19:53291for the user.
Junio C Hamano8638c922007-05-12 20:50:08292
Junio C Hamanoe48a1132016-08-03 22:40:21293The number of push options given on the command line of
294`git push --push-option=...` can be read from the environment
295variable `GIT_PUSH_OPTION_COUNT`, and the options themselves are
296found in `GIT_PUSH_OPTION_0`, `GIT_PUSH_OPTION_1`,...
297If it is negotiated to not use the push options phase, the
298environment variables will not be set. If the client selects
299to use push options, but doesn't transmit any, the count variable
300will be set to zero, `GIT_PUSH_OPTION_COUNT=0`.
301
Junio C Hamanoe25cc812017-04-24 06:17:43302See the section on "Quarantine Environment" in
303linkgit:git-receive-pack[1] for some caveats.
304
Junio C Hamano8638c922007-05-12 20:50:08305[[update]]
Junio C Hamano1a4e8412005-12-27 08:17:23306update
Junio C Hamanoc28068f2009-09-08 00:55:23307~~~~~~
Junio C Hamano1a4e8412005-12-27 08:17:23308
Junio C Hamanob9d9d902018-05-23 07:07:42309This hook is invoked by linkgit:git-receive-pack[1] when it reacts to
310`git push` and updates reference(s) in its repository.
Junio C Hamano818f7d62006-03-26 01:49:30311Just before updating the ref on the remote repository, the update hook
Junio C Hamano33db4372006-06-07 19:51:45312is invoked. Its exit status determines the success or failure of
Junio C Hamano818f7d62006-03-26 01:49:30313the ref update.
Junio C Hamano1a4e8412005-12-27 08:17:23314
Junio C Hamano818f7d62006-03-26 01:49:30315The hook executes once for each ref to be updated, and takes
316three parameters:
Junio C Hamanod5784132006-09-20 21:29:27317
318 - the name of the ref being updated,
319 - the old object name stored in the ref,
Junio C Hamano826f5c42014-02-07 20:33:30320 - and the new object name to be stored in the ref.
Junio C Hamano818f7d62006-03-26 01:49:30321
322A zero exit from the update hook allows the ref to be updated.
Junio C Hamanob9d9d902018-05-23 07:07:42323Exiting with a non-zero status prevents `git receive-pack`
Junio C Hamano8638c922007-05-12 20:50:08324from updating that ref.
Junio C Hamano818f7d62006-03-26 01:49:30325
326This hook can be used to prevent 'forced' update on certain refs by
Junio C Hamano1a4e8412005-12-27 08:17:23327making sure that the object name is a commit object that is a
328descendant of the commit object named by the old object name.
Junio C Hamano3f680f32009-11-16 02:10:54329That is, to enforce a "fast-forward only" policy.
Junio C Hamano818f7d62006-03-26 01:49:30330
331It could also be used to log the old..new status. However, it
332does not know the entire set of branches, so it would end up
Junio C Hamano8638c922007-05-12 20:50:08333firing one e-mail per ref when used naively, though. The
334<<post-receive,'post-receive'>> hook is more suited to that.
Junio C Hamano818f7d62006-03-26 01:49:30335
Junio C Hamano198b1f12016-05-17 22:27:24336In an environment that restricts the users' access only to git
337commands over the wire, this hook can be used to implement access
338control without relying on filesystem ownership and group
339membership. See linkgit:git-shell[1] for how you might use the login
340shell to restrict the user's access to only git commands.
Junio C Hamano1a4e8412005-12-27 08:17:23341
Junio C Hamano323e52d2007-05-13 22:19:53342Both standard output and standard error output are forwarded to
Junio C Hamanob9d9d902018-05-23 07:07:42343`git send-pack` on the other end, so you can simply `echo` messages
Junio C Hamano323e52d2007-05-13 22:19:53344for the user.
Junio C Hamano1a4e8412005-12-27 08:17:23345
Junio C Hamano8638c922007-05-12 20:50:08346The default 'update' hook, when enabled--and with
Junio C Hamanod6fff402009-09-14 09:40:50347`hooks.allowunannotated` config option unset or set to false--prevents
Junio C Hamano8638c922007-05-12 20:50:08348unannotated tags to be pushed.
Junio C Hamano818f7d62006-03-26 01:49:30349
Junio C Hamanoc562f6d2020-09-25 22:50:12350[[proc-receive]]
351proc-receive
352~~~~~~~~~~~~
353
354This hook is invoked by linkgit:git-receive-pack[1]. If the server has
355set the multi-valued config variable `receive.procReceiveRefs`, and the
356commands sent to 'receive-pack' have matching reference names, these
357commands will be executed by this hook, instead of by the internal
358`execute_commands()` function. This hook is responsible for updating
359the relevant references and reporting the results back to 'receive-pack'.
360
361This hook executes once for the receive operation. It takes no
362arguments, but uses a pkt-line format protocol to communicate with
363'receive-pack' to read commands, push-options and send results. In the
364following example for the protocol, the letter 'S' stands for
365'receive-pack' and the letter 'H' stands for this hook.
366
367 # Version and features negotiation.
368 S: PKT-LINE(version=1\0push-options atomic...)
369 S: flush-pkt
370 H: PKT-LINE(version=1\0push-options...)
371 H: flush-pkt
372
373 # Send commands from server to the hook.
374 S: PKT-LINE(<old-oid> <new-oid> <ref>)
375 S: ... ...
376 S: flush-pkt
377 # Send push-options only if the 'push-options' feature is enabled.
378 S: PKT-LINE(push-option)
379 S: ... ...
380 S: flush-pkt
381
382 # Receive result from the hook.
383 # OK, run this command successfully.
384 H: PKT-LINE(ok <ref>)
385 # NO, I reject it.
386 H: PKT-LINE(ng <ref> <reason>)
387 # Fall through, let 'receive-pack' to execute it.
388 H: PKT-LINE(ok <ref>)
389 H: PKT-LINE(option fall-through)
390 # OK, but has an alternate reference. The alternate reference name
391 # and other status can be given in option directives.
392 H: PKT-LINE(ok <ref>)
393 H: PKT-LINE(option refname <refname>)
394 H: PKT-LINE(option old-oid <old-oid>)
395 H: PKT-LINE(option new-oid <new-oid>)
396 H: PKT-LINE(option forced-update)
397 H: ... ...
398 H: flush-pkt
399
400Each command for the 'proc-receive' hook may point to a pseudo-reference
401and always has a zero-old as its old-oid, while the 'proc-receive' hook
402may update an alternate reference and the alternate reference may exist
403already with a non-zero old-oid. For this case, this hook will use
404"option" directives to report extended attributes for the reference given
405by the leading "ok" directive.
406
407The report of the commands of this hook should have the same order as
408the input. The exit status of the 'proc-receive' hook only determines
409the success or failure of the group of commands sent to it, unless
410atomic push is in use.
411
Junio C Hamano8638c922007-05-12 20:50:08412[[post-receive]]
413post-receive
Junio C Hamanoc28068f2009-09-08 00:55:23414~~~~~~~~~~~~
Junio C Hamano8638c922007-05-12 20:50:08415
Junio C Hamanob9d9d902018-05-23 07:07:42416This hook is invoked by linkgit:git-receive-pack[1] when it reacts to
417`git push` and updates reference(s) in its repository.
Junio C Hamano8638c922007-05-12 20:50:08418It executes on the remote repository once after all the refs have
419been updated.
420
421This hook executes once for the receive operation. It takes no
Junio C Hamano323e52d2007-05-13 22:19:53422arguments, but gets the same information as the
423<<pre-receive,'pre-receive'>>
Junio C Hamano8638c922007-05-12 20:50:08424hook does on its standard input.
425
Junio C Hamanob9d9d902018-05-23 07:07:42426This hook does not affect the outcome of `git receive-pack`, as it
Junio C Hamano8638c922007-05-12 20:50:08427is called after the real work is done.
428
Junio C Hamanoa6387422007-08-25 03:54:27429This supersedes the <<post-update,'post-update'>> hook in that it gets
Junio C Hamano323e52d2007-05-13 22:19:53430both old and new values of all the refs in addition to their
431names.
Junio C Hamano8638c922007-05-12 20:50:08432
Junio C Hamano323e52d2007-05-13 22:19:53433Both standard output and standard error output are forwarded to
Junio C Hamanob9d9d902018-05-23 07:07:42434`git send-pack` on the other end, so you can simply `echo` messages
Junio C Hamano323e52d2007-05-13 22:19:53435for the user.
Junio C Hamano8638c922007-05-12 20:50:08436
437The default 'post-receive' hook is empty, but there is
438a sample script `post-receive-email` provided in the `contrib/hooks`
Junio C Hamano076ffcc2013-02-06 05:13:21439directory in Git distribution, which implements sending commit
Junio C Hamano8638c922007-05-12 20:50:08440emails.
441
Junio C Hamanoe48a1132016-08-03 22:40:21442The number of push options given on the command line of
443`git push --push-option=...` can be read from the environment
444variable `GIT_PUSH_OPTION_COUNT`, and the options themselves are
445found in `GIT_PUSH_OPTION_0`, `GIT_PUSH_OPTION_1`,...
446If it is negotiated to not use the push options phase, the
447environment variables will not be set. If the client selects
448to use push options, but doesn't transmit any, the count variable
449will be set to zero, `GIT_PUSH_OPTION_COUNT=0`.
450
Junio C Hamano8638c922007-05-12 20:50:08451[[post-update]]
Junio C Hamano1a4e8412005-12-27 08:17:23452post-update
Junio C Hamanoc28068f2009-09-08 00:55:23453~~~~~~~~~~~
Junio C Hamano1a4e8412005-12-27 08:17:23454
Junio C Hamanob9d9d902018-05-23 07:07:42455This hook is invoked by linkgit:git-receive-pack[1] when it reacts to
456`git push` and updates reference(s) in its repository.
Junio C Hamano818f7d62006-03-26 01:49:30457It executes on the remote repository once after all the refs have
458been updated.
459
460It takes a variable number of parameters, each of which is the
461name of ref that was actually updated.
Junio C Hamano1a4e8412005-12-27 08:17:23462
463This hook is meant primarily for notification, and cannot affect
Junio C Hamanob9d9d902018-05-23 07:07:42464the outcome of `git receive-pack`.
Junio C Hamano1a4e8412005-12-27 08:17:23465
Junio C Hamanod5784132006-09-20 21:29:27466The 'post-update' hook can tell what are the heads that were pushed,
Junio C Hamano818f7d62006-03-26 01:49:30467but it does not know what their original and updated values are,
Junio C Hamano323e52d2007-05-13 22:19:53468so it is a poor place to do log old..new. The
469<<post-receive,'post-receive'>> hook does get both original and
470updated values of the refs. You might consider it instead if you need
471them.
Junio C Hamano8638c922007-05-12 20:50:08472
Junio C Hamanod5784132006-09-20 21:29:27473When enabled, the default 'post-update' hook runs
Junio C Hamanob9d9d902018-05-23 07:07:42474`git update-server-info` to keep the information used by dumb
Junio C Hamano88bf5712017-09-10 08:39:23475transports (e.g., HTTP) up to date. If you are publishing
Junio C Hamano076ffcc2013-02-06 05:13:21476a Git repository that is accessible via HTTP, you should
Junio C Hamano818f7d62006-03-26 01:49:30477probably enable this hook.
Junio C Hamano1a4e8412005-12-27 08:17:23478
Junio C Hamano8638c922007-05-12 20:50:08479Both standard output and standard error output are forwarded to
Junio C Hamanob9d9d902018-05-23 07:07:42480`git send-pack` on the other end, so you can simply `echo` messages
Junio C Hamano323e52d2007-05-13 22:19:53481for the user.
Junio C Hamanoe3ddb5b2008-04-21 00:48:07482
Junio C Hamanoc93f3212020-07-24 23:16:19483reference-transaction
484~~~~~~~~~~~~~~~~~~~~~
Junio C Hamanoa8911782020-07-07 05:35:57485
486This hook is invoked by any Git command that performs reference
487updates. It executes whenever a reference transaction is prepared,
Junio C Hamano458281a2021-03-22 21:20:26488committed or aborted and may thus get called multiple times. The hook
489does not cover symbolic references (but that may change in the future).
Junio C Hamanoa8911782020-07-07 05:35:57490
491The hook takes exactly one argument, which is the current state the
492given reference transaction is in:
493
494 - "prepared": All reference updates have been queued to the
495 transaction and references were locked on disk.
496
497 - "committed": The reference transaction was committed and all
498 references now have their respective new value.
499
500 - "aborted": The reference transaction was aborted, no changes
501 were performed and the locks have been released.
502
503For each reference update that was added to the transaction, the hook
504receives on standard input a line of the format:
505
506 <old-value> SP <new-value> SP <ref-name> LF
507
Junio C Hamano458281a2021-03-22 21:20:26508where `<old-value>` is the old object name passed into the reference
509transaction, `<new-value>` is the new object name to be stored in the
510ref and `<ref-name>` is the full name of the ref. When force updating
511the reference regardless of its current value or when the reference is
512to be created anew, `<old-value>` is the all-zeroes object name. To
513distinguish these cases, you can inspect the current value of
514`<ref-name>` via `git rev-parse`.
515
Junio C Hamanoa8911782020-07-07 05:35:57516The exit status of the hook is ignored for any state except for the
517"prepared" state. In the "prepared" state, a non-zero exit status will
518cause the transaction to be aborted. The hook will not be called with
519"aborted" state in that case.
520
Junio C Hamano6bb32e62015-02-17 22:11:26521push-to-checkout
522~~~~~~~~~~~~~~~~
523
Junio C Hamanob9d9d902018-05-23 07:07:42524This hook is invoked by linkgit:git-receive-pack[1] when it reacts to
525`git push` and updates reference(s) in its repository, and when
Junio C Hamano6bb32e62015-02-17 22:11:26526the push tries to update the branch that is currently checked out
527and the `receive.denyCurrentBranch` configuration variable is set to
528`updateInstead`. Such a push by default is refused if the working
529tree and the index of the remote repository has any difference from
530the currently checked out commit; when both the working tree and the
531index match the current commit, they are updated to match the newly
532pushed tip of the branch. This hook is to be used to override the
533default behaviour.
534
535The hook receives the commit with which the tip of the current
536branch is going to be updated. It can exit with a non-zero status
537to refuse the push (when it does so, it must not modify the index or
538the working tree). Or it can make any necessary changes to the
539working tree and to the index to bring them to the desired state
540when the tip of the current branch is updated to the new commit, and
541exit with a zero status.
542
543For example, the hook can simply run `git read-tree -u -m HEAD "$1"`
Junio C Hamanob9d9d902018-05-23 07:07:42544in order to emulate `git fetch` that is run in the reverse direction
545with `git push`, as the two-tree form of `git read-tree -u -m` is
Junio C Hamanoc9f11c22019-07-10 02:54:04546essentially the same as `git switch` or `git checkout`
547that switches branches while
Junio C Hamano6bb32e62015-02-17 22:11:26548keeping the local changes in the working tree that do not interfere
549with the difference between the branches.
550
551
Junio C Hamanoe3ddb5b2008-04-21 00:48:07552pre-auto-gc
Junio C Hamanoc28068f2009-09-08 00:55:23553~~~~~~~~~~~
Junio C Hamanoe3ddb5b2008-04-21 00:48:07554
Junio C Hamanob9d9d902018-05-23 07:07:42555This hook is invoked by `git gc --auto` (see linkgit:git-gc[1]). It
556takes no parameter, and exiting with non-zero status from this script
557causes the `git gc --auto` to abort.
Junio C Hamano2fbcd212008-05-14 22:26:07558
Junio C Hamano31667362010-03-25 00:38:53559post-rewrite
560~~~~~~~~~~~~
561
Junio C Hamanob9d9d902018-05-23 07:07:42562This hook is invoked by commands that rewrite commits
563(linkgit:git-commit[1] when called with `--amend` and
Junio C Hamanoa8858312019-09-30 05:07:45564linkgit:git-rebase[1]; however, full-history (re)writing tools like
565linkgit:git-fast-import[1] or
566https://github.com/newren/git-filter-repo[git-filter-repo] typically
567do not call it!). Its first argument denotes the command it was
568invoked by: currently one of `amend` or `rebase`. Further
569command-dependent arguments may be passed in the future.
Junio C Hamano31667362010-03-25 00:38:53570
571The hook receives a list of the rewritten commits on stdin, in the
572format
573
Junio C Hamano458281a2021-03-22 21:20:26574 <old-object-name> SP <new-object-name> [ SP <extra-info> ] LF
Junio C Hamano31667362010-03-25 00:38:53575
576The 'extra-info' is again command-dependent. If it is empty, the
577preceding SP is also omitted. Currently, no commands pass any
578'extra-info'.
579
580The hook always runs after the automatic note copying (see
Junio C Hamano96fdfa12016-03-21 20:52:39581"notes.rewrite.<command>" in linkgit:git-config[1]) has happened, and
Junio C Hamano31667362010-03-25 00:38:53582thus has access to these notes.
583
584The following command-specific comments apply:
585
586rebase::
587For the 'squash' and 'fixup' operation, all commits that were
588squashed are listed as being rewritten to the squashed commit.
589This means that there will be several lines sharing the same
Junio C Hamano458281a2021-03-22 21:20:26590'new-object-name'.
Junio C Hamano31667362010-03-25 00:38:53591+
592The commits are guaranteed to be listed in the order that they were
593processed by rebase.
594
Junio C Hamanod88ba732017-05-30 04:14:20595sendemail-validate
596~~~~~~~~~~~~~~~~~~
597
Junio C Hamano7ab2d202023-05-10 18:59:24598This hook is invoked by linkgit:git-send-email[1].
599
600It takes these command line arguments. They are,
6011. the name of the file which holds the contents of the email to be sent.
6022. The name of the file which holds the SMTP headers of the email.
603
604The SMTP headers are passed in the exact same way as they are passed to the
605user's Mail Transport Agent (MTA). In effect, the email given to the user's
606MTA, is the contents of $2 followed by the contents of $1.
607
608An example of a few common headers is shown below. Take notice of the
609capitalization and multi-line tab structure.
610
611 From: Example <from@example.com>
612 To: to@example.com
613 Cc: cc@example.com,
614 A <author@example.com>,
615 One <one@example.com>,
616 two@example.com
617 Subject: PATCH-STRING
618
619Exiting with a non-zero status causes `git send-email` to abort
620before sending any e-mails.
Junio C Hamanod88ba732017-05-30 04:14:20621
Junio C Hamano9f24e832023-04-25 21:41:32622The following environment variables are set when executing the hook.
623
624`GIT_SENDEMAIL_FILE_COUNTER`::
625A 1-based counter incremented by one for every file holding an e-mail
626to be sent (excluding any FIFOs). This counter does not follow the
627patch series counter scheme. It will always start at 1 and will end at
628GIT_SENDEMAIL_FILE_TOTAL.
629
630`GIT_SENDEMAIL_FILE_TOTAL`::
631The total number of files that will be sent (excluding any FIFOs). This
632counter does not follow the patch series counter scheme. It will always
633be equal to the number of files being sent, whether there is a cover
634letter or not.
635
636These variables may for instance be used to validate patch series.
637
638The sample `sendemail-validate` hook that comes with Git checks that all sent
639patches (excluding the cover letter) can be applied on top of the upstream
640repository default branch without conflicts. Some placeholders are left for
641additional validation steps to be performed after all patches of a given series
642have been applied.
643
Junio C Hamanod7105602017-11-21 05:32:50644fsmonitor-watchman
645~~~~~~~~~~~~~~~~~~
646
Junio C Hamanob9d9d902018-05-23 07:07:42647This hook is invoked when the configuration option `core.fsmonitor` is
Junio C Hamanofc6646b2020-02-14 23:35:16648set to `.git/hooks/fsmonitor-watchman` or `.git/hooks/fsmonitor-watchmanv2`
649depending on the version of the hook to use.
650
651Version 1 takes two arguments, a version (1) and the time in elapsed
652nanoseconds since midnight, January 1, 1970.
653
654Version 2 takes two arguments, a version (2) and a token that is used
655for identifying changes since the token. For watchman this would be
656a clock id. This version must output to stdout the new token followed
657by a NUL before the list of files.
Junio C Hamanod7105602017-11-21 05:32:50658
659The hook should output to stdout the list of all files in the working
660directory that may have changed since the requested time. The logic
661should be inclusive so that it does not miss any potential changes.
662The paths should be relative to the root of the working directory
663and be separated by a single NUL.
664
665It is OK to include files which have not actually changed. All changes
666including newly-created and deleted files should be included. When
667files are renamed, both the old and the new name should be included.
668
669Git will limit what files it checks for changes as well as which
670directories are checked for untracked files based on the path names
671given.
672
673An optimized way to tell git "all files have changed" is to return
Junio C Hamanob9d9d902018-05-23 07:07:42674the filename `/`.
Junio C Hamanod7105602017-11-21 05:32:50675
676The exit status determines whether git will use the data from the
677hook to limit its search. On error, it will fall back to verifying
678all files and folders.
Junio C Hamano31667362010-03-25 00:38:53679
Junio C Hamano67bf2242020-04-22 21:41:44680p4-changelist
681~~~~~~~~~~~~~
682
683This hook is invoked by `git-p4 submit`.
684
685The `p4-changelist` hook is executed after the changelist
686message has been edited by the user. It can be bypassed with the
687`--no-verify` option. It takes a single parameter, the name
688of the file that holds the proposed changelist text. Exiting
689with a non-zero status causes the command to abort.
690
691The hook is allowed to edit the changelist file and can be used
692to normalize the text into some project standard format. It can
693also be used to refuse the Submit after inspect the message file.
694
695Run `git-p4 submit --help` for details.
696
697p4-prepare-changelist
698~~~~~~~~~~~~~~~~~~~~~
699
700This hook is invoked by `git-p4 submit`.
701
702The `p4-prepare-changelist` hook is executed right after preparing
703the default changelist message and before the editor is started.
704It takes one parameter, the name of the file that contains the
705changelist text. Exiting with a non-zero status from the script
706will abort the process.
707
708The purpose of the hook is to edit the message file in place,
Junio C Hamanod5cfc8f2021-01-16 00:14:51709and it is not suppressed by the `--no-verify` option. This hook
Junio C Hamano67bf2242020-04-22 21:41:44710is called even if `--prepare-p4-only` is set.
711
712Run `git-p4 submit --help` for details.
713
714p4-post-changelist
715~~~~~~~~~~~~~~~~~~
716
717This hook is invoked by `git-p4 submit`.
718
719The `p4-post-changelist` hook is invoked after the submit has
Junio C Hamanoee43d182020-11-11 22:10:41720successfully occurred in P4. It takes no parameters and is meant
Junio C Hamano67bf2242020-04-22 21:41:44721primarily for notification and cannot affect the outcome of the
722git p4 submit action.
723
724Run `git-p4 submit --help` for details.
725
Junio C Hamanobfd91f42018-08-17 22:21:16726p4-pre-submit
727~~~~~~~~~~~~~
728
729This hook is invoked by `git-p4 submit`. It takes no parameters and nothing
730from standard input. Exiting with non-zero status from this script prevent
Junio C Hamano67bf2242020-04-22 21:41:44731`git-p4 submit` from launching. It can be bypassed with the `--no-verify`
732command line option. Run `git-p4 submit --help` for details.
733
734
Junio C Hamanobfd91f42018-08-17 22:21:16735
Junio C Hamano2ba14712019-04-25 10:12:27736post-index-change
737~~~~~~~~~~~~~~~~~
738
739This hook is invoked when the index is written in read-cache.c
740do_write_locked_index.
741
742The first parameter passed to the hook is the indicator for the
743working directory being updated. "1" meaning working directory
744was updated or "0" when the working directory was not updated.
745
746The second parameter passed to the hook is the indicator for whether
747or not the index was updated and the skip-worktree bit could have
748changed. "1" meaning skip-worktree bits could have been updated
749and "0" meaning they were not.
750
751Only one parameter should be set to "1" when the hook runs. The hook
752running passing "1", "1" should not be possible.
753
Junio C Hamanof1fc6ca2022-02-17 01:32:33754SEE ALSO
755--------
756linkgit:git-hook[1]
757
Junio C Hamano2fbcd212008-05-14 22:26:07758GIT
759---
Junio C Hamanof7c042d2008-06-06 22:50:53760Part of the linkgit:git[1] suite