1GITHOOKS(5)                       Git Manual                       GITHOOKS(5)
2
3
4

NAME

6       githooks - Hooks used by git
7

SYNOPSIS

9       $GIT_DIR/hooks/*
10

DESCRIPTION

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

HOOKS

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 SHA1 (if a -c, -C or --amend option was
84       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.
120
121   post-checkout
122       This hook is invoked when a git checkout is run after having updated
123       the worktree. The hook is given three parameters: the ref of the
124       previous HEAD, the ref of the new HEAD (which may or may not have
125       changed), and a flag indicating whether the checkout was a branch
126       checkout (changing branches, flag=1) or a file checkout (retrieving a
127       file from the index, flag=0). This hook cannot affect the outcome of
128       git checkout.
129
130       It is also run after git clone, unless the --no-checkout (-n) option is
131       used. The first parameter given to the hook is the null-ref, the second
132       the ref of the new HEAD and the flag is always 1.
133
134       This hook can be used to perform repository validity checks,
135       auto-display differences from the previous HEAD if different, or set
136       working dir metadata properties.
137
138   post-merge
139       This hook is invoked by git merge, which happens when a git pull is
140       done on a local repository. The hook takes a single parameter, a status
141       flag specifying whether or not the merge being done was a squash merge.
142       This hook cannot affect the outcome of git merge and is not executed,
143       if the merge failed due to conflicts.
144
145       This hook can be used in conjunction with a corresponding pre-commit
146       hook to save and restore any form of metadata associated with the
147       working tree (eg: permissions/ownership, ACLS, etc). See
148       contrib/hooks/setgitperms.perl for an example of how to do this.
149
150   pre-receive
151       This hook is invoked by git-receive-pack on the remote repository,
152       which happens when a git push is done on a local repository. Just
153       before starting to update refs on the remote repository, the
154       pre-receive hook is invoked. Its exit status determines the success or
155       failure of the update.
156
157       This hook executes once for the receive operation. It takes no
158       arguments, but for each ref to be updated it receives on standard input
159       a line of the format:
160
161           <old-value> SP <new-value> SP <ref-name> LF
162
163       where <old-value> is the old object name stored in the ref, <new-value>
164       is the new object name to be stored in the ref and <ref-name> is the
165       full name of the ref. When creating a new ref, <old-value> is 40 0.
166
167       If the hook exits with non-zero status, none of the refs will be
168       updated. If the hook exits with zero, updating of individual refs can
169       still be prevented by the update hook.
170
171       Both standard output and standard error output are forwarded to git
172       send-pack on the other end, so you can simply echo messages for the
173       user.
174
175   update
176       This hook is invoked by git-receive-pack on the remote repository,
177       which happens when a git push is done on a local repository. Just
178       before updating the ref on the remote repository, the update hook is
179       invoked. Its exit status determines the success or failure of the ref
180       update.
181
182       The hook executes once for each ref to be updated, and takes three
183       parameters:
184
185       ·   the name of the ref being updated,
186
187       ·   the old object name stored in the ref,
188
189       ·   and the new objectname to be stored in the ref.
190
191       A zero exit from the update hook allows the ref to be updated. Exiting
192       with a non-zero status prevents git-receive-pack from updating that
193       ref.
194
195       This hook can be used to prevent forced update on certain refs by
196       making sure that the object name is a commit object that is a
197       descendant of the commit object named by the old object name. That is,
198       to enforce a "fast-forward only" policy.
199
200       It could also be used to log the old..new status. However, it does not
201       know the entire set of branches, so it would end up firing one e-mail
202       per ref when used naively, though. The post-receive hook is more suited
203       to that.
204
205       Another use suggested on the mailing list is to use this hook to
206       implement access control which is finer grained than the one based on
207       filesystem group.
208
209       Both standard output and standard error output are forwarded to git
210       send-pack on the other end, so you can simply echo messages for the
211       user.
212
213       The default update hook, when enabled—and with hooks.allowunannotated
214       config option unset or set to false—prevents unannotated tags to be
215       pushed.
216
217   post-receive
218       This hook is invoked by git-receive-pack on the remote repository,
219       which happens when a git push is done on a local repository. It
220       executes on the remote repository once after all the refs have been
221       updated.
222
223       This hook executes once for the receive operation. It takes no
224       arguments, but gets the same information as the pre-receive hook does
225       on its standard input.
226
227       This hook does not affect the outcome of git-receive-pack, as it is
228       called after the real work is done.
229
230       This supersedes the post-update hook in that it gets both old and new
231       values of all the refs in addition to their names.
232
233       Both standard output and standard error output are forwarded to git
234       send-pack on the other end, so you can simply echo messages for the
235       user.
236
237       The default post-receive hook is empty, but there is a sample script
238       post-receive-email provided in the contrib/hooks directory in git
239       distribution, which implements sending commit emails.
240
241   post-update
242       This hook is invoked by git-receive-pack on the remote repository,
243       which happens when a git push is done on a local repository. It
244       executes on the remote repository once after all the refs have been
245       updated.
246
247       It takes a variable number of parameters, each of which is the name of
248       ref that was actually updated.
249
250       This hook is meant primarily for notification, and cannot affect the
251       outcome of git-receive-pack.
252
253       The post-update hook can tell what are the heads that were pushed, but
254       it does not know what their original and updated values are, so it is a
255       poor place to do log old..new. The post-receive hook does get both
256       original and updated values of the refs. You might consider it instead
257       if you need them.
258
259       When enabled, the default post-update hook runs git update-server-info
260       to keep the information used by dumb transports (e.g., HTTP)
261       up-to-date. If you are publishing a git repository that is accessible
262       via HTTP, you should probably enable this hook.
263
264       Both standard output and standard error output are forwarded to git
265       send-pack on the other end, so you can simply echo messages for the
266       user.
267
268   pre-auto-gc
269       This hook is invoked by git gc --auto. It takes no parameter, and
270       exiting with non-zero status from this script causes the git gc --auto
271       to abort.
272
273   post-rewrite
274       This hook is invoked by commands that rewrite commits (git commit
275       --amend, git-rebase; currently git-filter-branch does not call it!).
276       Its first argument denotes the command it was invoked by: currently one
277       of amend or rebase. Further command-dependent arguments may be passed
278       in the future.
279
280       The hook receives a list of the rewritten commits on stdin, in the
281       format
282
283           <old-sha1> SP <new-sha1> [ SP <extra-info> ] LF
284
285       The extra-info is again command-dependent. If it is empty, the
286       preceding SP is also omitted. Currently, no commands pass any
287       extra-info.
288
289       The hook always runs after the automatic note copying (see
290       "notes.rewrite.<command>" in linkgit:git-config.txt) has happened, and
291       thus has access to these notes.
292
293       The following command-specific comments apply:
294
295       rebase
296           For the squash and fixup operation, all commits that were squashed
297           are listed as being rewritten to the squashed commit. This means
298           that there will be several lines sharing the same new-sha1.
299
300           The commits are guaranteed to be listed in the order that they were
301           processed by rebase.
302
303       There is no default post-rewrite hook, but see the
304       post-receive-copy-notes script in contrib/hooks for an example that
305       copies your git-notes to the rewritten commits.
306

GIT

308       Part of the git(1) suite
309
310
311
312Git 1.7.1                         08/16/2017                       GITHOOKS(5)
Impressum