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