6 githooks - Hooks used by Git
10 $GIT_DIR/hooks/* (or \`git config core.hooksPath`/*)
16 Hooks are programs you can place in a hooks directory to trigger
17 actions at certain points in git's execution. Hooks that don't have
18 the executable bit set are ignored.
20 By default the hooks directory is `$GIT_DIR/hooks`, but that can be
21 changed via the `core.hooksPath` configuration variable (see
22 linkgit:git-config[1]).
24 Before Git invokes a hook, it changes its working directory to either
25 $GIT_DIR in a bare repository or the root of the working tree in a non-bare
26 repository. An exception are hooks triggered during a push ('pre-receive',
27 'update', 'post-receive', 'post-update', 'push-to-checkout') which are always
30 Hooks can get their arguments via the environment, command-line
31 arguments, and stdin. See the documentation for each hook below for
34 'git init' may copy hooks to the new repository, depending on its
35 configuration. See the "TEMPLATE DIRECTORY" section in
36 linkgit:git-init[1] for details. When the rest of this document refers
37 to "default hooks" it's talking about the default template shipped
40 The currently supported hooks are described below.
48 This hook is invoked by 'git am'. It takes a single
49 parameter, the name of the file that holds the proposed commit
50 log message. Exiting with a non-zero status causes 'git am' to abort
51 before applying the patch.
53 The hook is allowed to edit the message file in place, and can
54 be used to normalize the message into some project standard
55 format. It can also be used to refuse the commit after inspecting
58 The default 'applypatch-msg' hook, when enabled, runs the
59 'commit-msg' hook, if the latter is enabled.
64 This hook is invoked by 'git am'. It takes no parameter, and is
65 invoked after the patch is applied, but before a commit is made.
67 If it exits with non-zero status, then the working tree will not be
68 committed after applying the patch.
70 It can be used to inspect the current working tree and refuse to
71 make a commit if it does not pass certain test.
73 The default 'pre-applypatch' hook, when enabled, runs the
74 'pre-commit' hook, if the latter is enabled.
79 This hook is invoked by 'git am'. It takes no parameter,
80 and is invoked after the patch is applied and a commit is made.
82 This hook is meant primarily for notification, and cannot affect
83 the outcome of 'git am'.
88 This hook is invoked by 'git commit', and can be bypassed
89 with the `--no-verify` option. It takes no parameters, and is
90 invoked before obtaining the proposed commit log message and
91 making a commit. Exiting with a non-zero status from this script
92 causes the 'git commit' command to abort before creating a commit.
94 The default 'pre-commit' hook, when enabled, catches introduction
95 of lines with trailing whitespaces and aborts the commit when
98 All the 'git commit' hooks are invoked with the environment
99 variable `GIT_EDITOR=:` if the command will not bring up an editor
100 to modify the commit message.
105 This hook is invoked by 'git commit' right after preparing the
106 default log message, and before the editor is started.
108 It takes one to three parameters. The first is the name of the file
109 that contains the commit log message. The second is the source of the commit
110 message, and can be: `message` (if a `-m` or `-F` option was
111 given); `template` (if a `-t` option was given or the
112 configuration option `commit.template` is set); `merge` (if the
113 commit is a merge or a `.git/MERGE_MSG` file exists); `squash`
114 (if a `.git/SQUASH_MSG` file exists); or `commit`, followed by
115 a commit SHA-1 (if a `-c`, `-C` or `--amend` option was given).
117 If the exit status is non-zero, 'git commit' will abort.
119 The purpose of the hook is to edit the message file in place, and
120 it is not suppressed by the `--no-verify` option. A non-zero exit
121 means a failure of the hook and aborts the commit. It should not
122 be used as replacement for pre-commit hook.
124 The sample `prepare-commit-msg` hook that comes with Git removes the
125 help message found in the commented portion of the commit template.
130 This hook is invoked by 'git commit' and 'git merge', and can be
131 bypassed with the `--no-verify` option. It takes a single parameter,
132 the name of the file that holds the proposed commit log message.
133 Exiting with a non-zero status causes the command to abort.
135 The hook is allowed to edit the message file in place, and can be used
136 to normalize the message into some project standard format. It
137 can also be used to refuse the commit after inspecting the message
140 The default 'commit-msg' hook, when enabled, detects duplicate
141 "Signed-off-by" lines, and aborts the commit if one is found.
146 This hook is invoked by 'git commit'. It takes no parameters, and is
147 invoked after a commit is made.
149 This hook is meant primarily for notification, and cannot affect
150 the outcome of 'git commit'.
155 This hook is called by 'git rebase' and can be used to prevent a
156 branch from getting rebased. The hook may be called with one or
157 two parameters. The first parameter is the upstream from which
158 the series was forked. The second parameter is the branch being
159 rebased, and is not set when rebasing the current branch.
164 This hook is invoked when a 'git checkout' is run after having updated the
165 worktree. The hook is given three parameters: the ref of the previous HEAD,
166 the ref of the new HEAD (which may or may not have changed), and a flag
167 indicating whether the checkout was a branch checkout (changing branches,
168 flag=1) or a file checkout (retrieving a file from the index, flag=0).
169 This hook cannot affect the outcome of 'git checkout'.
171 It is also run after 'git clone', unless the --no-checkout (-n) option is
172 used. The first parameter given to the hook is the null-ref, the second the
173 ref of the new HEAD and the flag is always 1.
175 This hook can be used to perform repository validity checks, auto-display
176 differences from the previous HEAD if different, or set working dir metadata
182 This hook is invoked by 'git merge', which happens when a 'git pull'
183 is done on a local repository. The hook takes a single parameter, a status
184 flag specifying whether or not the merge being done was a squash merge.
185 This hook cannot affect the outcome of 'git merge' and is not executed,
186 if the merge failed due to conflicts.
188 This hook can be used in conjunction with a corresponding pre-commit hook to
189 save and restore any form of metadata associated with the working tree
190 (e.g.: permissions/ownership, ACLS, etc). See contrib/hooks/setgitperms.perl
191 for an example of how to do this.
196 This hook is called by 'git push' and can be used to prevent a push from taking
197 place. The hook is called with two parameters which provide the name and
198 location of the destination remote, if a named remote is not being used both
199 values will be the same.
201 Information about what is to be pushed is provided on the hook's standard
202 input with lines of the form:
204 <local ref> SP <local sha1> SP <remote ref> SP <remote sha1> LF
206 For instance, if the command +git push origin master:foreign+ were run the
207 hook would receive a line like the following:
209 refs/heads/master 67890 refs/heads/foreign 12345
211 although the full, 40-character SHA-1s would be supplied. If the foreign ref
212 does not yet exist the `<remote SHA-1>` will be 40 `0`. If a ref is to be
213 deleted, the `<local ref>` will be supplied as `(delete)` and the `<local
214 SHA-1>` will be 40 `0`. If the local commit was specified by something other
215 than a name which could be expanded (such as `HEAD~`, or a SHA-1) it will be
216 supplied as it was originally given.
218 If this hook exits with a non-zero status, 'git push' will abort without
219 pushing anything. Information about why the push is rejected may be sent
220 to the user by writing to standard error.
226 This hook is invoked by 'git-receive-pack' on the remote repository,
227 which happens when a 'git push' is done on a local repository.
228 Just before starting to update refs on the remote repository, the
229 pre-receive hook is invoked. Its exit status determines the success
230 or failure of the update.
232 This hook executes once for the receive operation. It takes no
233 arguments, but for each ref to be updated it receives on standard
234 input a line of the format:
236 <old-value> SP <new-value> SP <ref-name> LF
238 where `<old-value>` is the old object name stored in the ref,
239 `<new-value>` is the new object name to be stored in the ref and
240 `<ref-name>` is the full name of the ref.
241 When creating a new ref, `<old-value>` is 40 `0`.
243 If the hook exits with non-zero status, none of the refs will be
244 updated. If the hook exits with zero, updating of individual refs can
245 still be prevented by the <<update,'update'>> hook.
247 Both standard output and standard error output are forwarded to
248 'git send-pack' on the other end, so you can simply `echo` messages
251 The number of push options given on the command line of
252 `git push --push-option=...` can be read from the environment
253 variable `GIT_PUSH_OPTION_COUNT`, and the options themselves are
254 found in `GIT_PUSH_OPTION_0`, `GIT_PUSH_OPTION_1`,...
255 If it is negotiated to not use the push options phase, the
256 environment variables will not be set. If the client selects
257 to use push options, but doesn't transmit any, the count variable
258 will be set to zero, `GIT_PUSH_OPTION_COUNT=0`.
260 See the section on "Quarantine Environment" in
261 linkgit:git-receive-pack[1] for some caveats.
267 This hook is invoked by 'git-receive-pack' on the remote repository,
268 which happens when a 'git push' is done on a local repository.
269 Just before updating the ref on the remote repository, the update hook
270 is invoked. Its exit status determines the success or failure of
273 The hook executes once for each ref to be updated, and takes
276 - the name of the ref being updated,
277 - the old object name stored in the ref,
278 - and the new object name to be stored in the ref.
280 A zero exit from the update hook allows the ref to be updated.
281 Exiting with a non-zero status prevents 'git-receive-pack'
282 from updating that ref.
284 This hook can be used to prevent 'forced' update on certain refs by
285 making sure that the object name is a commit object that is a
286 descendant of the commit object named by the old object name.
287 That is, to enforce a "fast-forward only" policy.
289 It could also be used to log the old..new status. However, it
290 does not know the entire set of branches, so it would end up
291 firing one e-mail per ref when used naively, though. The
292 <<post-receive,'post-receive'>> hook is more suited to that.
294 In an environment that restricts the users' access only to git
295 commands over the wire, this hook can be used to implement access
296 control without relying on filesystem ownership and group
297 membership. See linkgit:git-shell[1] for how you might use the login
298 shell to restrict the user's access to only git commands.
300 Both standard output and standard error output are forwarded to
301 'git send-pack' on the other end, so you can simply `echo` messages
304 The default 'update' hook, when enabled--and with
305 `hooks.allowunannotated` config option unset or set to false--prevents
306 unannotated tags to be pushed.
312 This hook is invoked by 'git-receive-pack' on the remote repository,
313 which happens when a 'git push' is done on a local repository.
314 It executes on the remote repository once after all the refs have
317 This hook executes once for the receive operation. It takes no
318 arguments, but gets the same information as the
319 <<pre-receive,'pre-receive'>>
320 hook does on its standard input.
322 This hook does not affect the outcome of 'git-receive-pack', as it
323 is called after the real work is done.
325 This supersedes the <<post-update,'post-update'>> hook in that it gets
326 both old and new values of all the refs in addition to their
329 Both standard output and standard error output are forwarded to
330 'git send-pack' on the other end, so you can simply `echo` messages
333 The default 'post-receive' hook is empty, but there is
334 a sample script `post-receive-email` provided in the `contrib/hooks`
335 directory in Git distribution, which implements sending commit
338 The number of push options given on the command line of
339 `git push --push-option=...` can be read from the environment
340 variable `GIT_PUSH_OPTION_COUNT`, and the options themselves are
341 found in `GIT_PUSH_OPTION_0`, `GIT_PUSH_OPTION_1`,...
342 If it is negotiated to not use the push options phase, the
343 environment variables will not be set. If the client selects
344 to use push options, but doesn't transmit any, the count variable
345 will be set to zero, `GIT_PUSH_OPTION_COUNT=0`.
351 This hook is invoked by 'git-receive-pack' on the remote repository,
352 which happens when a 'git push' is done on a local repository.
353 It executes on the remote repository once after all the refs have
356 It takes a variable number of parameters, each of which is the
357 name of ref that was actually updated.
359 This hook is meant primarily for notification, and cannot affect
360 the outcome of 'git-receive-pack'.
362 The 'post-update' hook can tell what are the heads that were pushed,
363 but it does not know what their original and updated values are,
364 so it is a poor place to do log old..new. The
365 <<post-receive,'post-receive'>> hook does get both original and
366 updated values of the refs. You might consider it instead if you need
369 When enabled, the default 'post-update' hook runs
370 'git update-server-info' to keep the information used by dumb
371 transports (e.g., HTTP) up-to-date. If you are publishing
372 a Git repository that is accessible via HTTP, you should
373 probably enable this hook.
375 Both standard output and standard error output are forwarded to
376 'git send-pack' on the other end, so you can simply `echo` messages
382 This hook is invoked by 'git-receive-pack' on the remote repository,
383 which happens when a 'git push' is done on a local repository, when
384 the push tries to update the branch that is currently checked out
385 and the `receive.denyCurrentBranch` configuration variable is set to
386 `updateInstead`. Such a push by default is refused if the working
387 tree and the index of the remote repository has any difference from
388 the currently checked out commit; when both the working tree and the
389 index match the current commit, they are updated to match the newly
390 pushed tip of the branch. This hook is to be used to override the
393 The hook receives the commit with which the tip of the current
394 branch is going to be updated. It can exit with a non-zero status
395 to refuse the push (when it does so, it must not modify the index or
396 the working tree). Or it can make any necessary changes to the
397 working tree and to the index to bring them to the desired state
398 when the tip of the current branch is updated to the new commit, and
399 exit with a zero status.
401 For example, the hook can simply run `git read-tree -u -m HEAD "$1"`
402 in order to emulate 'git fetch' that is run in the reverse direction
403 with `git push`, as the two-tree form of `read-tree -u -m` is
404 essentially the same as `git checkout` that switches branches while
405 keeping the local changes in the working tree that do not interfere
406 with the difference between the branches.
412 This hook is invoked by 'git gc --auto'. It takes no parameter, and
413 exiting with non-zero status from this script causes the 'git gc --auto'
419 This hook is invoked by commands that rewrite commits (`git commit
420 --amend`, 'git-rebase'; currently 'git-filter-branch' does 'not' call
421 it!). Its first argument denotes the command it was invoked by:
422 currently one of `amend` or `rebase`. Further command-dependent
423 arguments may be passed in the future.
425 The hook receives a list of the rewritten commits on stdin, in the
428 <old-sha1> SP <new-sha1> [ SP <extra-info> ] LF
430 The 'extra-info' is again command-dependent. If it is empty, the
431 preceding SP is also omitted. Currently, no commands pass any
434 The hook always runs after the automatic note copying (see
435 "notes.rewrite.<command>" in linkgit:git-config[1]) has happened, and
436 thus has access to these notes.
438 The following command-specific comments apply:
441 For the 'squash' and 'fixup' operation, all commits that were
442 squashed are listed as being rewritten to the squashed commit.
443 This means that there will be several lines sharing the same
446 The commits are guaranteed to be listed in the order that they were
452 This hook is invoked by 'git send-email'. It takes a single parameter,
453 the name of the file that holds the e-mail to be sent. Exiting with a
454 non-zero status causes 'git send-email' to abort before sending any
460 Part of the linkgit:git[1] suite