]>
Commit | Line | Data |
---|---|---|
a5af0e2c CC |
1 | githooks(5) |
2 | =========== | |
3 | ||
4 | NAME | |
5 | ---- | |
2de9b711 | 6 | githooks - Hooks used by Git |
a5af0e2c CC |
7 | |
8 | SYNOPSIS | |
9 | -------- | |
10 | $GIT_DIR/hooks/* | |
11 | ||
12 | ||
13 | DESCRIPTION | |
14 | ----------- | |
6d35cc76 JH |
15 | |
16 | Hooks are little scripts you can place in `$GIT_DIR/hooks` | |
17 | directory to trigger action at certain points. When | |
0b444cdb | 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 |
20 | all disabled. To enable a hook, rename it by removing its `.sample` |
21 | suffix. | |
6d35cc76 | 22 | |
1df27132 MV |
23 | NOTE: It is also a requirement for a given hook to be executable. |
24 | However - in a freshly initialized repository - the `.sample` files are | |
25 | executable by default. | |
26 | ||
6d35cc76 JH |
27 | This document describes the currently defined hooks. |
28 | ||
6d71c1dc BW |
29 | HOOKS |
30 | ----- | |
31 | ||
6d35cc76 | 32 | applypatch-msg |
6d71c1dc | 33 | ~~~~~~~~~~~~~~ |
6d35cc76 | 34 | |
0b444cdb | 35 | This hook is invoked by 'git am' script. It takes a single |
6d35cc76 | 36 | parameter, the name of the file that holds the proposed commit |
45ad9b50 | 37 | log message. Exiting with non-zero status causes |
0b444cdb | 38 | 'git am' to abort before applying the patch. |
6d35cc76 JH |
39 | |
40 | The hook is allowed to edit the message file in place, and can | |
41 | be used to normalize the message into some project standard | |
42 | format (if the project has one). It can also be used to refuse | |
43 | the commit after inspecting the message file. | |
44 | ||
45ad9b50 JF |
45 | The default 'applypatch-msg' hook, when enabled, runs the |
46 | 'commit-msg' hook, if the latter is enabled. | |
6d35cc76 JH |
47 | |
48 | pre-applypatch | |
6d71c1dc | 49 | ~~~~~~~~~~~~~~ |
6d35cc76 | 50 | |
0b444cdb | 51 | This hook is invoked by 'git am'. It takes no parameter, and is |
47458bb9 CC |
52 | invoked after the patch is applied, but before a commit is made. |
53 | ||
54 | If it exits with non-zero status, then the working tree will not be | |
55 | committed after applying the patch. | |
6d35cc76 JH |
56 | |
57 | It can be used to inspect the current working tree and refuse to | |
58 | make a commit if it does not pass certain test. | |
59 | ||
45ad9b50 JF |
60 | The default 'pre-applypatch' hook, when enabled, runs the |
61 | 'pre-commit' hook, if the latter is enabled. | |
6d35cc76 JH |
62 | |
63 | post-applypatch | |
6d71c1dc | 64 | ~~~~~~~~~~~~~~~ |
6d35cc76 | 65 | |
0b444cdb | 66 | This hook is invoked by 'git am'. It takes no parameter, |
6d35cc76 JH |
67 | and is invoked after the patch is applied and a commit is made. |
68 | ||
69 | This hook is meant primarily for notification, and cannot affect | |
0b444cdb | 70 | the outcome of 'git am'. |
6d35cc76 JH |
71 | |
72 | pre-commit | |
6d71c1dc | 73 | ~~~~~~~~~~ |
6d35cc76 | 74 | |
0b444cdb | 75 | This hook is invoked by 'git commit', and can be bypassed |
6cf378f0 | 76 | with `--no-verify` option. It takes no parameter, and is |
6d35cc76 JH |
77 | invoked before obtaining the proposed commit log message and |
78 | making a commit. Exiting with non-zero status from this script | |
0b444cdb | 79 | causes the 'git commit' to abort. |
6d35cc76 | 80 | |
45ad9b50 | 81 | The default 'pre-commit' hook, when enabled, catches introduction |
6d35cc76 | 82 | of lines with trailing whitespaces and aborts the commit when |
45ad9b50 | 83 | such a line is found. |
6d35cc76 | 84 | |
0b444cdb | 85 | All the 'git commit' hooks are invoked with the environment |
406400ce PB |
86 | variable `GIT_EDITOR=:` if the command will not bring up an editor |
87 | to modify the commit message. | |
88 | ||
8089c85b | 89 | prepare-commit-msg |
6d71c1dc | 90 | ~~~~~~~~~~~~~~~~~~ |
8089c85b | 91 | |
0b444cdb | 92 | This hook is invoked by 'git commit' right after preparing the |
8089c85b PB |
93 | default log message, and before the editor is started. |
94 | ||
95 | It takes one to three parameters. The first is the name of the file | |
99686960 | 96 | that contains the commit log message. The second is the source of the commit |
5d6b3a9e SG |
97 | message, and can be: `message` (if a `-m` or `-F` option was |
98 | given); `template` (if a `-t` option was given or the | |
8089c85b PB |
99 | configuration option `commit.template` is set); `merge` (if the |
100 | commit is a merge or a `.git/MERGE_MSG` file exists); `squash` | |
101 | (if a `.git/SQUASH_MSG` file exists); or `commit`, followed by | |
d5fa1f1a | 102 | a commit SHA-1 (if a `-c`, `-C` or `--amend` option was given). |
8089c85b | 103 | |
0b444cdb | 104 | If the exit status is non-zero, 'git commit' will abort. |
8089c85b PB |
105 | |
106 | The purpose of the hook is to edit the message file in place, and | |
6cf378f0 | 107 | it is not suppressed by the `--no-verify` option. A non-zero exit |
8089c85b PB |
108 | means a failure of the hook and aborts the commit. It should not |
109 | be used as replacement for pre-commit hook. | |
110 | ||
2de9b711 | 111 | The sample `prepare-commit-msg` hook that comes with Git comments |
8089c85b PB |
112 | out the `Conflicts:` part of a merge's commit message. |
113 | ||
6d35cc76 | 114 | commit-msg |
6d71c1dc | 115 | ~~~~~~~~~~ |
6d35cc76 | 116 | |
0b444cdb | 117 | This hook is invoked by 'git commit', and can be bypassed |
6cf378f0 | 118 | with `--no-verify` option. It takes a single parameter, the |
6d35cc76 | 119 | name of the file that holds the proposed commit log message. |
0b444cdb | 120 | Exiting with non-zero status causes the 'git commit' to |
6d35cc76 JH |
121 | abort. |
122 | ||
123 | The hook is allowed to edit the message file in place, and can | |
124 | be used to normalize the message into some project standard | |
125 | format (if the project has one). It can also be used to refuse | |
126 | the commit after inspecting the message file. | |
127 | ||
45ad9b50 JF |
128 | The default 'commit-msg' hook, when enabled, detects duplicate |
129 | "Signed-off-by" lines, and aborts the commit if one is found. | |
6d35cc76 JH |
130 | |
131 | post-commit | |
6d71c1dc | 132 | ~~~~~~~~~~~ |
6d35cc76 | 133 | |
0b444cdb | 134 | This hook is invoked by 'git commit'. It takes no |
6d35cc76 JH |
135 | parameter, and is invoked after a commit is made. |
136 | ||
137 | This hook is meant primarily for notification, and cannot affect | |
0b444cdb | 138 | the outcome of 'git commit'. |
6d35cc76 | 139 | |
00e5d48a | 140 | pre-rebase |
6d71c1dc | 141 | ~~~~~~~~~~ |
00e5d48a | 142 | |
0414acc3 TK |
143 | This hook is called by 'git rebase' and can be used to prevent a |
144 | branch from getting rebased. The hook may be called with one or | |
145 | two parameters. The first parameter is the upstream from which | |
146 | the series was forked. The second parameter is the branch being | |
147 | rebased, and is not set when rebasing the current branch. | |
00e5d48a | 148 | |
1abbe475 | 149 | post-checkout |
6d71c1dc | 150 | ~~~~~~~~~~~~~ |
1abbe475 | 151 | |
0b444cdb | 152 | This hook is invoked when a 'git checkout' is run after having updated the |
1abbe475 JE |
153 | worktree. The hook is given three parameters: the ref of the previous HEAD, |
154 | the ref of the new HEAD (which may or may not have changed), and a flag | |
155 | indicating whether the checkout was a branch checkout (changing branches, | |
156 | flag=1) or a file checkout (retrieving a file from the index, flag=0). | |
0b444cdb | 157 | This hook cannot affect the outcome of 'git checkout'. |
1abbe475 | 158 | |
0b444cdb | 159 | It is also run after 'git clone', unless the --no-checkout (-n) option is |
24c11552 JL |
160 | used. The first parameter given to the hook is the null-ref, the second the |
161 | ref of the new HEAD and the flag is always 1. | |
162 | ||
1abbe475 JE |
163 | This hook can be used to perform repository validity checks, auto-display |
164 | differences from the previous HEAD if different, or set working dir metadata | |
165 | properties. | |
166 | ||
46232915 | 167 | post-merge |
6d71c1dc | 168 | ~~~~~~~~~~ |
46232915 | 169 | |
0b444cdb | 170 | This hook is invoked by 'git merge', which happens when a 'git pull' |
46232915 JE |
171 | is done on a local repository. The hook takes a single parameter, a status |
172 | flag specifying whether or not the merge being done was a squash merge. | |
0b444cdb | 173 | This hook cannot affect the outcome of 'git merge' and is not executed, |
2b3e60c2 | 174 | if the merge failed due to conflicts. |
46232915 JE |
175 | |
176 | This hook can be used in conjunction with a corresponding pre-commit hook to | |
177 | save and restore any form of metadata associated with the working tree | |
af6fb4c8 JE |
178 | (eg: permissions/ownership, ACLS, etc). See contrib/hooks/setgitperms.perl |
179 | for an example of how to do this. | |
46232915 | 180 | |
ec55559f AS |
181 | pre-push |
182 | ~~~~~~~~ | |
183 | ||
184 | This hook is called by 'git push' and can be used to prevent a push from taking | |
185 | place. The hook is called with two parameters which provide the name and | |
186 | location of the destination remote, if a named remote is not being used both | |
187 | values will be the same. | |
188 | ||
189 | Information about what is to be pushed is provided on the hook's standard | |
190 | input with lines of the form: | |
191 | ||
192 | <local ref> SP <local sha1> SP <remote ref> SP <remote sha1> LF | |
193 | ||
194 | For instance, if the command +git push origin master:foreign+ were run the | |
195 | hook would receive a line like the following: | |
196 | ||
197 | refs/heads/master 67890 refs/heads/foreign 12345 | |
198 | ||
d5fa1f1a TA |
199 | although the full, 40-character SHA-1s would be supplied. If the foreign ref |
200 | does not yet exist the `<remote SHA-1>` will be 40 `0`. If a ref is to be | |
ec55559f | 201 | deleted, the `<local ref>` will be supplied as `(delete)` and the `<local |
d5fa1f1a TA |
202 | SHA-1>` will be 40 `0`. If the local commit was specified by something other |
203 | than a name which could be expanded (such as `HEAD~`, or a SHA-1) it will be | |
ec55559f AS |
204 | supplied as it was originally given. |
205 | ||
206 | If this hook exits with a non-zero status, 'git push' will abort without | |
207 | pushing anything. Information about why the push is rejected may be sent | |
208 | to the user by writing to standard error. | |
209 | ||
cbb84e5d JH |
210 | [[pre-receive]] |
211 | pre-receive | |
6d71c1dc | 212 | ~~~~~~~~~~~ |
cbb84e5d | 213 | |
ba020ef5 | 214 | This hook is invoked by 'git-receive-pack' on the remote repository, |
0b444cdb | 215 | which happens when a 'git push' is done on a local repository. |
cbb84e5d JH |
216 | Just before starting to update refs on the remote repository, the |
217 | pre-receive hook is invoked. Its exit status determines the success | |
218 | or failure of the update. | |
219 | ||
220 | This hook executes once for the receive operation. It takes no | |
221 | arguments, but for each ref to be updated it receives on standard | |
222 | input a line of the format: | |
223 | ||
224 | <old-value> SP <new-value> SP <ref-name> LF | |
225 | ||
226 | where `<old-value>` is the old object name stored in the ref, | |
227 | `<new-value>` is the new object name to be stored in the ref and | |
228 | `<ref-name>` is the full name of the ref. | |
229 | When creating a new ref, `<old-value>` is 40 `0`. | |
230 | ||
231 | If the hook exits with non-zero status, none of the refs will be | |
232 | updated. If the hook exits with zero, updating of individual refs can | |
233 | still be prevented by the <<update,'update'>> hook. | |
234 | ||
24a0d61e | 235 | Both standard output and standard error output are forwarded to |
0b444cdb | 236 | 'git send-pack' on the other end, so you can simply `echo` messages |
24a0d61e | 237 | for the user. |
cbb84e5d JH |
238 | |
239 | [[update]] | |
6d35cc76 | 240 | update |
6d71c1dc | 241 | ~~~~~~ |
6d35cc76 | 242 | |
ba020ef5 | 243 | This hook is invoked by 'git-receive-pack' on the remote repository, |
0b444cdb | 244 | which happens when a 'git push' is done on a local repository. |
6250ad1e | 245 | Just before updating the ref on the remote repository, the update hook |
37425065 | 246 | is invoked. Its exit status determines the success or failure of |
6250ad1e JL |
247 | the ref update. |
248 | ||
249 | The hook executes once for each ref to be updated, and takes | |
250 | three parameters: | |
45ad9b50 JF |
251 | |
252 | - the name of the ref being updated, | |
253 | - the old object name stored in the ref, | |
254 | - and the new objectname to be stored in the ref. | |
6250ad1e JL |
255 | |
256 | A zero exit from the update hook allows the ref to be updated. | |
ba020ef5 | 257 | Exiting with a non-zero status prevents 'git-receive-pack' |
cbb84e5d | 258 | from updating that ref. |
6250ad1e JL |
259 | |
260 | This hook can be used to prevent 'forced' update on certain refs by | |
6d35cc76 JH |
261 | making sure that the object name is a commit object that is a |
262 | descendant of the commit object named by the old object name. | |
a75d7b54 | 263 | That is, to enforce a "fast-forward only" policy. |
6250ad1e JL |
264 | |
265 | It could also be used to log the old..new status. However, it | |
266 | does not know the entire set of branches, so it would end up | |
cbb84e5d JH |
267 | firing one e-mail per ref when used naively, though. The |
268 | <<post-receive,'post-receive'>> hook is more suited to that. | |
6250ad1e | 269 | |
6d35cc76 JH |
270 | Another use suggested on the mailing list is to use this hook to |
271 | implement access control which is finer grained than the one | |
272 | based on filesystem group. | |
273 | ||
24a0d61e | 274 | Both standard output and standard error output are forwarded to |
0b444cdb | 275 | 'git send-pack' on the other end, so you can simply `echo` messages |
24a0d61e | 276 | for the user. |
3aadad1b | 277 | |
cbb84e5d | 278 | The default 'update' hook, when enabled--and with |
39c448c1 | 279 | `hooks.allowunannotated` config option unset or set to false--prevents |
cbb84e5d JH |
280 | unannotated tags to be pushed. |
281 | ||
282 | [[post-receive]] | |
283 | post-receive | |
6d71c1dc | 284 | ~~~~~~~~~~~~ |
6250ad1e | 285 | |
ba020ef5 | 286 | This hook is invoked by 'git-receive-pack' on the remote repository, |
0b444cdb | 287 | which happens when a 'git push' is done on a local repository. |
cbb84e5d JH |
288 | It executes on the remote repository once after all the refs have |
289 | been updated. | |
290 | ||
291 | This hook executes once for the receive operation. It takes no | |
24a0d61e JH |
292 | arguments, but gets the same information as the |
293 | <<pre-receive,'pre-receive'>> | |
cbb84e5d JH |
294 | hook does on its standard input. |
295 | ||
ba020ef5 | 296 | This hook does not affect the outcome of 'git-receive-pack', as it |
cbb84e5d JH |
297 | is called after the real work is done. |
298 | ||
02783075 | 299 | This supersedes the <<post-update,'post-update'>> hook in that it gets |
24a0d61e JH |
300 | both old and new values of all the refs in addition to their |
301 | names. | |
cbb84e5d | 302 | |
24a0d61e | 303 | Both standard output and standard error output are forwarded to |
0b444cdb | 304 | 'git send-pack' on the other end, so you can simply `echo` messages |
24a0d61e | 305 | for the user. |
cbb84e5d JH |
306 | |
307 | The default 'post-receive' hook is empty, but there is | |
308 | a sample script `post-receive-email` provided in the `contrib/hooks` | |
2de9b711 | 309 | directory in Git distribution, which implements sending commit |
cbb84e5d JH |
310 | emails. |
311 | ||
312 | [[post-update]] | |
6d35cc76 | 313 | post-update |
6d71c1dc | 314 | ~~~~~~~~~~~ |
6d35cc76 | 315 | |
ba020ef5 | 316 | This hook is invoked by 'git-receive-pack' on the remote repository, |
0b444cdb | 317 | which happens when a 'git push' is done on a local repository. |
6250ad1e JL |
318 | It executes on the remote repository once after all the refs have |
319 | been updated. | |
320 | ||
321 | It takes a variable number of parameters, each of which is the | |
322 | name of ref that was actually updated. | |
6d35cc76 JH |
323 | |
324 | This hook is meant primarily for notification, and cannot affect | |
ba020ef5 | 325 | the outcome of 'git-receive-pack'. |
6d35cc76 | 326 | |
45ad9b50 | 327 | The 'post-update' hook can tell what are the heads that were pushed, |
6250ad1e | 328 | but it does not know what their original and updated values are, |
24a0d61e JH |
329 | so it is a poor place to do log old..new. The |
330 | <<post-receive,'post-receive'>> hook does get both original and | |
331 | updated values of the refs. You might consider it instead if you need | |
332 | them. | |
cbb84e5d | 333 | |
45ad9b50 | 334 | When enabled, the default 'post-update' hook runs |
0b444cdb | 335 | 'git update-server-info' to keep the information used by dumb |
45ad9b50 | 336 | transports (e.g., HTTP) up-to-date. If you are publishing |
2de9b711 | 337 | a Git repository that is accessible via HTTP, you should |
6250ad1e | 338 | probably enable this hook. |
3aadad1b | 339 | |
cbb84e5d | 340 | Both standard output and standard error output are forwarded to |
0b444cdb | 341 | 'git send-pack' on the other end, so you can simply `echo` messages |
24a0d61e | 342 | for the user. |
0b85d926 MV |
343 | |
344 | pre-auto-gc | |
6d71c1dc | 345 | ~~~~~~~~~~~ |
0b85d926 | 346 | |
0b444cdb TR |
347 | This hook is invoked by 'git gc --auto'. It takes no parameter, and |
348 | exiting with non-zero status from this script causes the 'git gc --auto' | |
0b85d926 | 349 | to abort. |
a5af0e2c | 350 | |
c0fc6869 TR |
351 | post-rewrite |
352 | ~~~~~~~~~~~~ | |
353 | ||
354 | This hook is invoked by commands that rewrite commits (`git commit | |
355 | --amend`, 'git-rebase'; currently 'git-filter-branch' does 'not' call | |
356 | it!). Its first argument denotes the command it was invoked by: | |
357 | currently one of `amend` or `rebase`. Further command-dependent | |
358 | arguments may be passed in the future. | |
359 | ||
360 | The hook receives a list of the rewritten commits on stdin, in the | |
361 | format | |
362 | ||
363 | <old-sha1> SP <new-sha1> [ SP <extra-info> ] LF | |
364 | ||
365 | The 'extra-info' is again command-dependent. If it is empty, the | |
366 | preceding SP is also omitted. Currently, no commands pass any | |
367 | 'extra-info'. | |
368 | ||
6956f858 | 369 | The hook always runs after the automatic note copying (see |
5e248584 | 370 | "notes.rewrite.<command>" in linkgit:git-config.txt[1]) has happened, and |
6956f858 TR |
371 | thus has access to these notes. |
372 | ||
c0fc6869 TR |
373 | The following command-specific comments apply: |
374 | ||
375 | rebase:: | |
376 | For the 'squash' and 'fixup' operation, all commits that were | |
377 | squashed are listed as being rewritten to the squashed commit. | |
378 | This means that there will be several lines sharing the same | |
379 | 'new-sha1'. | |
380 | + | |
381 | The commits are guaranteed to be listed in the order that they were | |
382 | processed by rebase. | |
383 | ||
c0fc6869 | 384 | |
a5af0e2c CC |
385 | GIT |
386 | --- | |
9e1f0a85 | 387 | Part of the linkgit:git[1] suite |