]> git.ipfire.org Git - thirdparty/git.git/blame - Documentation/githooks.txt
GIT 1.6.5
[thirdparty/git.git] / Documentation / githooks.txt
CommitLineData
a5af0e2c
CC
1githooks(5)
2===========
3
4NAME
5----
6githooks - Hooks used by git
7
8SYNOPSIS
9--------
10$GIT_DIR/hooks/*
11
12
13DESCRIPTION
14-----------
6d35cc76
JH
15
16Hooks are little scripts you can place in `$GIT_DIR/hooks`
17directory to trigger action at certain points. When
323b9db8 18'git-init' is run, a handful of example hooks are copied into the
6d35cc76 19`hooks` directory of the new repository, but by default they are
f98f8cba
JH
20all disabled. To enable a hook, rename it by removing its `.sample`
21suffix.
6d35cc76 22
1df27132
MV
23NOTE: 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
6d35cc76
JH
27This document describes the currently defined hooks.
28
6d71c1dc
BW
29HOOKS
30-----
31
6d35cc76 32applypatch-msg
6d71c1dc 33~~~~~~~~~~~~~~
6d35cc76 34
ba020ef5 35This hook is invoked by 'git-am' script. It takes a single
6d35cc76 36parameter, the name of the file that holds the proposed commit
45ad9b50 37log message. Exiting with non-zero status causes
ba020ef5 38'git-am' to abort before applying the patch.
6d35cc76
JH
39
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
45ad9b50
JF
45The default 'applypatch-msg' hook, when enabled, runs the
46'commit-msg' hook, if the latter is enabled.
6d35cc76
JH
47
48pre-applypatch
6d71c1dc 49~~~~~~~~~~~~~~
6d35cc76 50
ba020ef5 51This hook is invoked by 'git-am'. It takes no parameter, and is
47458bb9
CC
52invoked 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.
6d35cc76
JH
56
57It can be used to inspect the current working tree and refuse to
58make a commit if it does not pass certain test.
59
45ad9b50
JF
60The default 'pre-applypatch' hook, when enabled, runs the
61'pre-commit' hook, if the latter is enabled.
6d35cc76
JH
62
63post-applypatch
6d71c1dc 64~~~~~~~~~~~~~~~
6d35cc76 65
ba020ef5 66This hook is invoked by 'git-am'. It takes no parameter,
6d35cc76
JH
67and is invoked after the patch is applied and a commit is made.
68
69This hook is meant primarily for notification, and cannot affect
ba020ef5 70the outcome of 'git-am'.
6d35cc76
JH
71
72pre-commit
6d71c1dc 73~~~~~~~~~~
6d35cc76 74
ba020ef5 75This hook is invoked by 'git-commit', and can be bypassed
e1ccf53a 76with `\--no-verify` option. It takes no parameter, and is
6d35cc76
JH
77invoked before obtaining the proposed commit log message and
78making a commit. Exiting with non-zero status from this script
ba020ef5 79causes the 'git-commit' to abort.
6d35cc76 80
45ad9b50 81The default 'pre-commit' hook, when enabled, catches introduction
6d35cc76 82of lines with trailing whitespaces and aborts the commit when
45ad9b50 83such a line is found.
6d35cc76 84
ba020ef5 85All the 'git-commit' hooks are invoked with the environment
406400ce
PB
86variable `GIT_EDITOR=:` if the command will not bring up an editor
87to modify the commit message.
88
8089c85b 89prepare-commit-msg
6d71c1dc 90~~~~~~~~~~~~~~~~~~
8089c85b 91
ba020ef5 92This hook is invoked by 'git-commit' right after preparing the
8089c85b
PB
93default log message, and before the editor is started.
94
95It takes one to three parameters. The first is the name of the file
99686960 96that contains the commit log message. The second is the source of the commit
5d6b3a9e
SG
97message, and can be: `message` (if a `-m` or `-F` option was
98given); `template` (if a `-t` option was given or the
8089c85b
PB
99configuration 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
5d6b3a9e 102a commit SHA1 (if a `-c`, `-C` or `\--amend` option was given).
8089c85b 103
ba020ef5 104If the exit status is non-zero, 'git-commit' will abort.
8089c85b
PB
105
106The purpose of the hook is to edit the message file in place, and
107it is not suppressed by the `\--no-verify` option. A non-zero exit
108means a failure of the hook and aborts the commit. It should not
109be used as replacement for pre-commit hook.
110
111The sample `prepare-commit-msg` hook that comes with git comments
112out the `Conflicts:` part of a merge's commit message.
113
6d35cc76 114commit-msg
6d71c1dc 115~~~~~~~~~~
6d35cc76 116
ba020ef5 117This hook is invoked by 'git-commit', and can be bypassed
e1ccf53a 118with `\--no-verify` option. It takes a single parameter, the
6d35cc76 119name of the file that holds the proposed commit log message.
ba020ef5 120Exiting with non-zero status causes the 'git-commit' to
6d35cc76
JH
121abort.
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
45ad9b50
JF
128The default 'commit-msg' hook, when enabled, detects duplicate
129"Signed-off-by" lines, and aborts the commit if one is found.
6d35cc76
JH
130
131post-commit
6d71c1dc 132~~~~~~~~~~~
6d35cc76 133
ba020ef5 134This hook is invoked by 'git-commit'. It takes no
6d35cc76
JH
135parameter, and is invoked after a commit is made.
136
137This hook is meant primarily for notification, and cannot affect
ba020ef5 138the outcome of 'git-commit'.
6d35cc76 139
00e5d48a 140pre-rebase
6d71c1dc 141~~~~~~~~~~
00e5d48a
NS
142
143This hook is called by 'git-rebase' and can be used to prevent a branch
144from getting rebased.
145
146
1abbe475 147post-checkout
6d71c1dc 148~~~~~~~~~~~~~
1abbe475 149
ba020ef5 150This hook is invoked when a 'git-checkout' is run after having updated the
1abbe475
JE
151worktree. 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).
ba020ef5 155This hook cannot affect the outcome of 'git-checkout'.
1abbe475 156
24c11552
JL
157It is also run after 'git-clone', unless the --no-checkout (-n) option is
158used. 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
1abbe475
JE
161This 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
46232915 165post-merge
6d71c1dc 166~~~~~~~~~~
46232915 167
ba020ef5 168This hook is invoked by 'git-merge', which happens when a 'git-pull'
46232915
JE
169is 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.
ba020ef5 171This hook cannot affect the outcome of 'git-merge' and is not executed,
2b3e60c2 172if the merge failed due to conflicts.
46232915
JE
173
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
af6fb4c8
JE
176(eg: permissions/ownership, ACLS, etc). See contrib/hooks/setgitperms.perl
177for an example of how to do this.
46232915 178
cbb84e5d
JH
179[[pre-receive]]
180pre-receive
6d71c1dc 181~~~~~~~~~~~
cbb84e5d 182
ba020ef5
JN
183This hook is invoked by 'git-receive-pack' on the remote repository,
184which happens when a 'git-push' is done on a local repository.
cbb84e5d
JH
185Just before starting to update refs on the remote repository, the
186pre-receive hook is invoked. Its exit status determines the success
187or failure of the update.
188
189This hook executes once for the receive operation. It takes no
190arguments, but for each ref to be updated it receives on standard
191input a line of the format:
192
193 <old-value> SP <new-value> SP <ref-name> LF
194
195where `<old-value>` is the old object name stored in the ref,
196`<new-value>` is the new object name to be stored in the ref and
197`<ref-name>` is the full name of the ref.
198When creating a new ref, `<old-value>` is 40 `0`.
199
200If the hook exits with non-zero status, none of the refs will be
201updated. If the hook exits with zero, updating of individual refs can
202still be prevented by the <<update,'update'>> hook.
203
24a0d61e 204Both standard output and standard error output are forwarded to
ba020ef5 205'git-send-pack' on the other end, so you can simply `echo` messages
24a0d61e 206for the user.
cbb84e5d
JH
207
208[[update]]
6d35cc76 209update
6d71c1dc 210~~~~~~
6d35cc76 211
ba020ef5
JN
212This hook is invoked by 'git-receive-pack' on the remote repository,
213which happens when a 'git-push' is done on a local repository.
6250ad1e 214Just before updating the ref on the remote repository, the update hook
37425065 215is invoked. Its exit status determines the success or failure of
6250ad1e
JL
216the ref update.
217
218The hook executes once for each ref to be updated, and takes
219three parameters:
45ad9b50
JF
220
221 - the name of the ref being updated,
222 - the old object name stored in the ref,
223 - and the new objectname to be stored in the ref.
6250ad1e
JL
224
225A zero exit from the update hook allows the ref to be updated.
ba020ef5 226Exiting with a non-zero status prevents 'git-receive-pack'
cbb84e5d 227from updating that ref.
6250ad1e
JL
228
229This hook can be used to prevent 'forced' update on certain refs by
6d35cc76
JH
230making sure that the object name is a commit object that is a
231descendant of the commit object named by the old object name.
6250ad1e
JL
232That is, to enforce a "fast forward only" policy.
233
234It could also be used to log the old..new status. However, it
235does not know the entire set of branches, so it would end up
cbb84e5d
JH
236firing one e-mail per ref when used naively, though. The
237<<post-receive,'post-receive'>> hook is more suited to that.
6250ad1e 238
6d35cc76
JH
239Another use suggested on the mailing list is to use this hook to
240implement access control which is finer grained than the one
241based on filesystem group.
242
24a0d61e 243Both standard output and standard error output are forwarded to
ba020ef5 244'git-send-pack' on the other end, so you can simply `echo` messages
24a0d61e 245for the user.
3aadad1b 246
cbb84e5d 247The default 'update' hook, when enabled--and with
39c448c1 248`hooks.allowunannotated` config option unset or set to false--prevents
cbb84e5d
JH
249unannotated tags to be pushed.
250
251[[post-receive]]
252post-receive
6d71c1dc 253~~~~~~~~~~~~
6250ad1e 254
ba020ef5
JN
255This hook is invoked by 'git-receive-pack' on the remote repository,
256which happens when a 'git-push' is done on a local repository.
cbb84e5d
JH
257It executes on the remote repository once after all the refs have
258been updated.
259
260This hook executes once for the receive operation. It takes no
24a0d61e
JH
261arguments, but gets the same information as the
262<<pre-receive,'pre-receive'>>
cbb84e5d
JH
263hook does on its standard input.
264
ba020ef5 265This hook does not affect the outcome of 'git-receive-pack', as it
cbb84e5d
JH
266is called after the real work is done.
267
02783075 268This supersedes the <<post-update,'post-update'>> hook in that it gets
24a0d61e
JH
269both old and new values of all the refs in addition to their
270names.
cbb84e5d 271
24a0d61e 272Both standard output and standard error output are forwarded to
ba020ef5 273'git-send-pack' on the other end, so you can simply `echo` messages
24a0d61e 274for the user.
cbb84e5d
JH
275
276The default 'post-receive' hook is empty, but there is
277a sample script `post-receive-email` provided in the `contrib/hooks`
278directory in git distribution, which implements sending commit
279emails.
280
281[[post-update]]
6d35cc76 282post-update
6d71c1dc 283~~~~~~~~~~~
6d35cc76 284
ba020ef5
JN
285This hook is invoked by 'git-receive-pack' on the remote repository,
286which happens when a 'git-push' is done on a local repository.
6250ad1e
JL
287It executes on the remote repository once after all the refs have
288been updated.
289
290It takes a variable number of parameters, each of which is the
291name of ref that was actually updated.
6d35cc76
JH
292
293This hook is meant primarily for notification, and cannot affect
ba020ef5 294the outcome of 'git-receive-pack'.
6d35cc76 295
45ad9b50 296The 'post-update' hook can tell what are the heads that were pushed,
6250ad1e 297but it does not know what their original and updated values are,
24a0d61e
JH
298so it is a poor place to do log old..new. The
299<<post-receive,'post-receive'>> hook does get both original and
300updated values of the refs. You might consider it instead if you need
301them.
cbb84e5d 302
45ad9b50 303When enabled, the default 'post-update' hook runs
ba020ef5 304'git-update-server-info' to keep the information used by dumb
45ad9b50
JF
305transports (e.g., HTTP) up-to-date. If you are publishing
306a git repository that is accessible via HTTP, you should
6250ad1e 307probably enable this hook.
3aadad1b 308
cbb84e5d 309Both standard output and standard error output are forwarded to
ba020ef5 310'git-send-pack' on the other end, so you can simply `echo` messages
24a0d61e 311for the user.
0b85d926 312
a8563ec8
JH
313post-upload-pack
314----------------
315
316After upload-pack successfully finishes its operation, this hook is called
317for logging purposes.
318
319The hook is passed various pieces of information, one per line, from its
320standard input. Currently the following items can be fed to the hook, but
321more types of information may be added in the future:
322
323want SHA-1::
324 40-byte hexadecimal object name the client asked to include in the
325 resulting pack. Can occur one or more times in the input.
326
327have SHA-1::
328 40-byte hexadecimal object name the client asked to exclude from
329 the resulting pack, claiming to have them already. Can occur zero
330 or more times in the input.
331
332time float::
333 Number of seconds spent for creating the packfile.
334
335size decimal::
336 Size of the resulting packfile in bytes.
337
11cae066
JH
338kind string:
339 Either "clone" (when the client did not give us any "have", and asked
340 for all our refs with "want"), or "fetch" (otherwise).
341
0b85d926 342pre-auto-gc
6d71c1dc 343~~~~~~~~~~~
0b85d926 344
ba020ef5
JN
345This 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'
0b85d926 347to abort.
a5af0e2c
CC
348
349GIT
350---
9e1f0a85 351Part of the linkgit:git[1] suite