4 Hooks are little scripts you can place in `$GIT_DIR/hooks`
5 directory to trigger action at certain points. When
6 `git-init` is run, a handful example hooks are copied in the
7 `hooks` directory of the new repository, but by default they are
8 all disabled. To enable a hook, make it executable with `chmod +x`.
10 This document describes the currently defined hooks.
15 This hook is invoked by `git-am` script. It takes a single
16 parameter, the name of the file that holds the proposed commit
17 log message. Exiting with non-zero status causes
18 `git-am` to abort before applying the patch.
20 The hook is allowed to edit the message file in place, and can
21 be used to normalize the message into some project standard
22 format (if the project has one). It can also be used to refuse
23 the commit after inspecting the message file.
25 The default 'applypatch-msg' hook, when enabled, runs the
26 'commit-msg' hook, if the latter is enabled.
31 This hook is invoked by `git-am`. It takes no parameter,
32 and is invoked after the patch is applied, but before a commit
33 is made. Exiting with non-zero status causes the working tree
34 after application of the patch not committed.
36 It can be used to inspect the current working tree and refuse to
37 make a commit if it does not pass certain test.
39 The default 'pre-applypatch' hook, when enabled, runs the
40 'pre-commit' hook, if the latter is enabled.
45 This hook is invoked by `git-am`. It takes no parameter,
46 and is invoked after the patch is applied and a commit is made.
48 This hook is meant primarily for notification, and cannot affect
49 the outcome of `git-am`.
54 This hook is invoked by `git-commit`, and can be bypassed
55 with `\--no-verify` option. It takes no parameter, and is
56 invoked before obtaining the proposed commit log message and
57 making a commit. Exiting with non-zero status from this script
58 causes the `git-commit` to abort.
60 The default 'pre-commit' hook, when enabled, catches introduction
61 of lines with trailing whitespaces and aborts the commit when
67 This hook is invoked by `git-commit`, and can be bypassed
68 with `\--no-verify` option. It takes a single parameter, the
69 name of the file that holds the proposed commit log message.
70 Exiting with non-zero status causes the `git-commit` to
73 The hook is allowed to edit the message file in place, and can
74 be used to normalize the message into some project standard
75 format (if the project has one). It can also be used to refuse
76 the commit after inspecting the message file.
78 The default 'commit-msg' hook, when enabled, detects duplicate
79 "Signed-off-by" lines, and aborts the commit if one is found.
84 This hook is invoked by `git-commit`. It takes no
85 parameter, and is invoked after a commit is made.
87 This hook is meant primarily for notification, and cannot affect
88 the outcome of `git-commit`.
93 This hook is invoked when a `git-checkout` is run after having updated the
94 worktree. The hook is given three parameters: the ref of the previous HEAD,
95 the ref of the new HEAD (which may or may not have changed), and a flag
96 indicating whether the checkout was a branch checkout (changing branches,
97 flag=1) or a file checkout (retrieving a file from the index, flag=0).
98 This hook cannot affect the outcome of `git-checkout`.
100 This hook can be used to perform repository validity checks, auto-display
101 differences from the previous HEAD if different, or set working dir metadata
107 This hook is invoked by `git-merge`, which happens when a `git pull`
108 is done on a local repository. The hook takes a single parameter, a status
109 flag specifying whether or not the merge being done was a squash merge.
110 This hook cannot affect the outcome of `git-merge`.
112 This hook can be used in conjunction with a corresponding pre-commit hook to
113 save and restore any form of metadata associated with the working tree
114 (eg: permissions/ownership, ACLS, etc). See contrib/hooks/setgitperms.perl
115 for an example of how to do this.
121 This hook is invoked by `git-receive-pack` on the remote repository,
122 which happens when a `git push` is done on a local repository.
123 Just before starting to update refs on the remote repository, the
124 pre-receive hook is invoked. Its exit status determines the success
125 or failure of the update.
127 This hook executes once for the receive operation. It takes no
128 arguments, but for each ref to be updated it receives on standard
129 input a line of the format:
131 <old-value> SP <new-value> SP <ref-name> LF
133 where `<old-value>` is the old object name stored in the ref,
134 `<new-value>` is the new object name to be stored in the ref and
135 `<ref-name>` is the full name of the ref.
136 When creating a new ref, `<old-value>` is 40 `0`.
138 If the hook exits with non-zero status, none of the refs will be
139 updated. If the hook exits with zero, updating of individual refs can
140 still be prevented by the <<update,'update'>> hook.
142 Both standard output and standard error output are forwarded to
143 `git-send-pack` on the other end, so you can simply `echo` messages
150 This hook is invoked by `git-receive-pack` on the remote repository,
151 which happens when a `git push` is done on a local repository.
152 Just before updating the ref on the remote repository, the update hook
153 is invoked. Its exit status determines the success or failure of
156 The hook executes once for each ref to be updated, and takes
159 - the name of the ref being updated,
160 - the old object name stored in the ref,
161 - and the new objectname to be stored in the ref.
163 A zero exit from the update hook allows the ref to be updated.
164 Exiting with a non-zero status prevents `git-receive-pack`
165 from updating that ref.
167 This hook can be used to prevent 'forced' update on certain refs by
168 making sure that the object name is a commit object that is a
169 descendant of the commit object named by the old object name.
170 That is, to enforce a "fast forward only" policy.
172 It could also be used to log the old..new status. However, it
173 does not know the entire set of branches, so it would end up
174 firing one e-mail per ref when used naively, though. The
175 <<post-receive,'post-receive'>> hook is more suited to that.
177 Another use suggested on the mailing list is to use this hook to
178 implement access control which is finer grained than the one
179 based on filesystem group.
181 Both standard output and standard error output are forwarded to
182 `git-send-pack` on the other end, so you can simply `echo` messages
185 The default 'update' hook, when enabled--and with
186 `hooks.allowunannotated` config option turned on--prevents
187 unannotated tags to be pushed.
193 This hook is invoked by `git-receive-pack` on the remote repository,
194 which happens when a `git push` is done on a local repository.
195 It executes on the remote repository once after all the refs have
198 This hook executes once for the receive operation. It takes no
199 arguments, but gets the same information as the
200 <<pre-receive,'pre-receive'>>
201 hook does on its standard input.
203 This hook does not affect the outcome of `git-receive-pack`, as it
204 is called after the real work is done.
206 This supersedes the <<post-update,'post-update'>> hook in that it gets
207 both old and new values of all the refs in addition to their
210 Both standard output and standard error output are forwarded to
211 `git-send-pack` on the other end, so you can simply `echo` messages
214 The default 'post-receive' hook is empty, but there is
215 a sample script `post-receive-email` provided in the `contrib/hooks`
216 directory in git distribution, which implements sending commit
223 This hook is invoked by `git-receive-pack` on the remote repository,
224 which happens when a `git push` is done on a local repository.
225 It executes on the remote repository once after all the refs have
228 It takes a variable number of parameters, each of which is the
229 name of ref that was actually updated.
231 This hook is meant primarily for notification, and cannot affect
232 the outcome of `git-receive-pack`.
234 The 'post-update' hook can tell what are the heads that were pushed,
235 but it does not know what their original and updated values are,
236 so it is a poor place to do log old..new. The
237 <<post-receive,'post-receive'>> hook does get both original and
238 updated values of the refs. You might consider it instead if you need
241 When enabled, the default 'post-update' hook runs
242 `git-update-server-info` to keep the information used by dumb
243 transports (e.g., HTTP) up-to-date. If you are publishing
244 a git repository that is accessible via HTTP, you should
245 probably enable this 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