Junio C Hamano | 2fbcd21 | 2008-05-14 22:26:07 | [diff] [blame] | 1 | githooks(5) |
| 2 | =========== |
| 3 | |
| 4 | NAME |
| 5 | ---- |
Junio C Hamano | 076ffcc | 2013-02-06 05:13:21 | [diff] [blame] | 6 | githooks - Hooks used by Git |
Junio C Hamano | 2fbcd21 | 2008-05-14 22:26:07 | [diff] [blame] | 7 | |
| 8 | SYNOPSIS |
| 9 | -------- |
Junio C Hamano | 198b1f1 | 2016-05-17 22:27:24 | [diff] [blame] | 10 | $GIT_DIR/hooks/* (or \`git config core.hooksPath`/*) |
Junio C Hamano | 2fbcd21 | 2008-05-14 22:26:07 | [diff] [blame] | 11 | |
| 12 | |
| 13 | DESCRIPTION |
| 14 | ----------- |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 15 | |
Junio C Hamano | 198b1f1 | 2016-05-17 22:27:24 | [diff] [blame] | 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. |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 19 | |
Junio C Hamano | 198b1f1 | 2016-05-17 22:27:24 | [diff] [blame] | 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]). |
Junio C Hamano | 8a48fa2 | 2008-12-18 08:44:30 | [diff] [blame] | 23 | |
Junio C Hamano | 198b1f1 | 2016-05-17 22:27:24 | [diff] [blame] | 24 | Before Git invokes a hook, it changes its working directory to either |
Junio C Hamano | 4c60d9a | 2017-05-04 14:36:22 | [diff] [blame] | 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 |
| 28 | executed in $GIT_DIR. |
Junio C Hamano | 198b1f1 | 2016-05-17 22:27:24 | [diff] [blame] | 29 | |
| 30 | Hooks can get their arguments via the environment, command-line |
| 31 | arguments, and stdin. See the documentation for each hook below for |
| 32 | details. |
| 33 | |
Junio C Hamano | b9d9d90 | 2018-05-23 07:07:42 | [diff] [blame] | 34 | `git init` may copy hooks to the new repository, depending on its |
Junio C Hamano | 198b1f1 | 2016-05-17 22:27:24 | [diff] [blame] | 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 |
| 38 | with Git. |
| 39 | |
| 40 | The currently supported hooks are described below. |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 41 | |
Junio C Hamano | c28068f | 2009-09-08 00:55:23 | [diff] [blame] | 42 | HOOKS |
| 43 | ----- |
| 44 | |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 45 | applypatch-msg |
Junio C Hamano | c28068f | 2009-09-08 00:55:23 | [diff] [blame] | 46 | ~~~~~~~~~~~~~~ |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 47 | |
Junio C Hamano | b9d9d90 | 2018-05-23 07:07:42 | [diff] [blame] | 48 | This hook is invoked by linkgit:git-am[1]. It takes a single |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 49 | parameter, the name of the file that holds the proposed commit |
Junio C Hamano | b9d9d90 | 2018-05-23 07:07:42 | [diff] [blame] | 50 | log message. Exiting with a non-zero status causes `git am` to abort |
Junio C Hamano | 198b1f1 | 2016-05-17 22:27:24 | [diff] [blame] | 51 | before applying the patch. |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 52 | |
| 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 |
Junio C Hamano | 198b1f1 | 2016-05-17 22:27:24 | [diff] [blame] | 55 | format. It can also be used to refuse the commit after inspecting |
| 56 | the message file. |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 57 | |
Junio C Hamano | d578413 | 2006-09-20 21:29:27 | [diff] [blame] | 58 | The default 'applypatch-msg' hook, when enabled, runs the |
| 59 | 'commit-msg' hook, if the latter is enabled. |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 60 | |
| 61 | pre-applypatch |
Junio C Hamano | c28068f | 2009-09-08 00:55:23 | [diff] [blame] | 62 | ~~~~~~~~~~~~~~ |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 63 | |
Junio C Hamano | b9d9d90 | 2018-05-23 07:07:42 | [diff] [blame] | 64 | This hook is invoked by linkgit:git-am[1]. It takes no parameter, and is |
Junio C Hamano | a31092a | 2008-05-04 06:41:23 | [diff] [blame] | 65 | invoked after the patch is applied, but before a commit is made. |
| 66 | |
| 67 | If it exits with non-zero status, then the working tree will not be |
| 68 | committed after applying the patch. |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 69 | |
| 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. |
| 72 | |
Junio C Hamano | d578413 | 2006-09-20 21:29:27 | [diff] [blame] | 73 | The default 'pre-applypatch' hook, when enabled, runs the |
| 74 | 'pre-commit' hook, if the latter is enabled. |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 75 | |
| 76 | post-applypatch |
Junio C Hamano | c28068f | 2009-09-08 00:55:23 | [diff] [blame] | 77 | ~~~~~~~~~~~~~~~ |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 78 | |
Junio C Hamano | b9d9d90 | 2018-05-23 07:07:42 | [diff] [blame] | 79 | This hook is invoked by linkgit:git-am[1]. It takes no parameter, |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 80 | and is invoked after the patch is applied and a commit is made. |
| 81 | |
| 82 | This hook is meant primarily for notification, and cannot affect |
Junio C Hamano | b9d9d90 | 2018-05-23 07:07:42 | [diff] [blame] | 83 | the outcome of `git am`. |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 84 | |
| 85 | pre-commit |
Junio C Hamano | c28068f | 2009-09-08 00:55:23 | [diff] [blame] | 86 | ~~~~~~~~~~ |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 87 | |
Junio C Hamano | b9d9d90 | 2018-05-23 07:07:42 | [diff] [blame] | 88 | This hook is invoked by linkgit:git-commit[1], and can be bypassed |
Junio C Hamano | 198b1f1 | 2016-05-17 22:27:24 | [diff] [blame] | 89 | with the `--no-verify` option. It takes no parameters, and is |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 90 | invoked before obtaining the proposed commit log message and |
Junio C Hamano | 198b1f1 | 2016-05-17 22:27:24 | [diff] [blame] | 91 | making a commit. Exiting with a non-zero status from this script |
Junio C Hamano | b9d9d90 | 2018-05-23 07:07:42 | [diff] [blame] | 92 | causes the `git commit` command to abort before creating a commit. |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 93 | |
Junio C Hamano | d578413 | 2006-09-20 21:29:27 | [diff] [blame] | 94 | The default 'pre-commit' hook, when enabled, catches introduction |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 95 | of lines with trailing whitespaces and aborts the commit when |
Junio C Hamano | d578413 | 2006-09-20 21:29:27 | [diff] [blame] | 96 | such a line is found. |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 97 | |
Junio C Hamano | b9d9d90 | 2018-05-23 07:07:42 | [diff] [blame] | 98 | All the `git commit` hooks are invoked with the environment |
Junio C Hamano | 26e590a | 2008-02-17 03:53:51 | [diff] [blame] | 99 | variable `GIT_EDITOR=:` if the command will not bring up an editor |
| 100 | to modify the commit message. |
| 101 | |
Junio C Hamano | 11f1537 | 2019-03-07 03:17:00 | [diff] [blame] | 102 | The default 'pre-commit' hook, when enabled--and with the |
| 103 | `hooks.allownonascii` config option unset or set to false--prevents |
| 104 | the use of non-ASCII filenames. |
| 105 | |
Junio C Hamano | cb70539 | 2019-09-18 19:30:01 | [diff] [blame] | 106 | pre-merge-commit |
| 107 | ~~~~~~~~~~~~~~~~ |
| 108 | |
| 109 | This hook is invoked by linkgit:git-merge[1], and can be bypassed |
| 110 | with the `--no-verify` option. It takes no parameters, and is |
| 111 | invoked after the merge has been carried out successfully and before |
| 112 | obtaining the proposed commit log message to |
| 113 | make a commit. Exiting with a non-zero status from this script |
| 114 | causes the `git merge` command to abort before creating a commit. |
| 115 | |
| 116 | The default 'pre-merge-commit' hook, when enabled, runs the |
| 117 | 'pre-commit' hook, if the latter is enabled. |
| 118 | |
| 119 | This hook is invoked with the environment variable |
| 120 | `GIT_EDITOR=:` if the command will not bring up an editor |
| 121 | to modify the commit message. |
| 122 | |
| 123 | If the merge cannot be carried out automatically, the conflicts |
| 124 | need to be resolved and the result committed separately (see |
| 125 | linkgit:git-merge[1]). At that point, this hook will not be executed, |
| 126 | but the 'pre-commit' hook will, if it is enabled. |
| 127 | |
Junio C Hamano | 26e590a | 2008-02-17 03:53:51 | [diff] [blame] | 128 | prepare-commit-msg |
Junio C Hamano | c28068f | 2009-09-08 00:55:23 | [diff] [blame] | 129 | ~~~~~~~~~~~~~~~~~~ |
Junio C Hamano | 26e590a | 2008-02-17 03:53:51 | [diff] [blame] | 130 | |
Junio C Hamano | b9d9d90 | 2018-05-23 07:07:42 | [diff] [blame] | 131 | This hook is invoked by linkgit:git-commit[1] right after preparing the |
Junio C Hamano | 26e590a | 2008-02-17 03:53:51 | [diff] [blame] | 132 | default log message, and before the editor is started. |
| 133 | |
| 134 | It takes one to three parameters. The first is the name of the file |
Junio C Hamano | bd53dbf | 2009-01-18 18:26:37 | [diff] [blame] | 135 | that contains the commit log message. The second is the source of the commit |
Junio C Hamano | a476efa | 2008-10-10 15:31:42 | [diff] [blame] | 136 | message, and can be: `message` (if a `-m` or `-F` option was |
| 137 | given); `template` (if a `-t` option was given or the |
Junio C Hamano | 26e590a | 2008-02-17 03:53:51 | [diff] [blame] | 138 | configuration option `commit.template` is set); `merge` (if the |
| 139 | commit is a merge or a `.git/MERGE_MSG` file exists); `squash` |
| 140 | (if a `.git/SQUASH_MSG` file exists); or `commit`, followed by |
Junio C Hamano | e3f080d | 2013-04-22 02:27:13 | [diff] [blame] | 141 | a commit SHA-1 (if a `-c`, `-C` or `--amend` option was given). |
Junio C Hamano | 26e590a | 2008-02-17 03:53:51 | [diff] [blame] | 142 | |
Junio C Hamano | b9d9d90 | 2018-05-23 07:07:42 | [diff] [blame] | 143 | If the exit status is non-zero, `git commit` will abort. |
Junio C Hamano | 26e590a | 2008-02-17 03:53:51 | [diff] [blame] | 144 | |
| 145 | The purpose of the hook is to edit the message file in place, and |
Junio C Hamano | b76a686 | 2012-05-02 22:02:46 | [diff] [blame] | 146 | it is not suppressed by the `--no-verify` option. A non-zero exit |
Junio C Hamano | 26e590a | 2008-02-17 03:53:51 | [diff] [blame] | 147 | means a failure of the hook and aborts the commit. It should not |
| 148 | be used as replacement for pre-commit hook. |
| 149 | |
Junio C Hamano | 4b2a6c1 | 2017-08-22 18:32:37 | [diff] [blame] | 150 | The sample `prepare-commit-msg` hook that comes with Git removes the |
| 151 | help message found in the commented portion of the commit template. |
Junio C Hamano | 26e590a | 2008-02-17 03:53:51 | [diff] [blame] | 152 | |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 153 | commit-msg |
Junio C Hamano | c28068f | 2009-09-08 00:55:23 | [diff] [blame] | 154 | ~~~~~~~~~~ |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 155 | |
Junio C Hamano | b9d9d90 | 2018-05-23 07:07:42 | [diff] [blame] | 156 | This hook is invoked by linkgit:git-commit[1] and linkgit:git-merge[1], and can be |
Junio C Hamano | ef75f37 | 2017-09-29 04:22:33 | [diff] [blame] | 157 | bypassed with the `--no-verify` option. It takes a single parameter, |
| 158 | the name of the file that holds the proposed commit log message. |
| 159 | Exiting with a non-zero status causes the command to abort. |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 160 | |
Junio C Hamano | 198b1f1 | 2016-05-17 22:27:24 | [diff] [blame] | 161 | The hook is allowed to edit the message file in place, and can be used |
| 162 | to normalize the message into some project standard format. It |
| 163 | can also be used to refuse the commit after inspecting the message |
| 164 | file. |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 165 | |
Junio C Hamano | d578413 | 2006-09-20 21:29:27 | [diff] [blame] | 166 | The default 'commit-msg' hook, when enabled, detects duplicate |
| 167 | "Signed-off-by" lines, and aborts the commit if one is found. |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 168 | |
| 169 | post-commit |
Junio C Hamano | c28068f | 2009-09-08 00:55:23 | [diff] [blame] | 170 | ~~~~~~~~~~~ |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 171 | |
Junio C Hamano | b9d9d90 | 2018-05-23 07:07:42 | [diff] [blame] | 172 | This hook is invoked by linkgit:git-commit[1]. It takes no parameters, and is |
Junio C Hamano | 198b1f1 | 2016-05-17 22:27:24 | [diff] [blame] | 173 | invoked after a commit is made. |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 174 | |
| 175 | This hook is meant primarily for notification, and cannot affect |
Junio C Hamano | b9d9d90 | 2018-05-23 07:07:42 | [diff] [blame] | 176 | the outcome of `git commit`. |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 177 | |
Junio C Hamano | a476efa | 2008-10-10 15:31:42 | [diff] [blame] | 178 | pre-rebase |
Junio C Hamano | c28068f | 2009-09-08 00:55:23 | [diff] [blame] | 179 | ~~~~~~~~~~ |
Junio C Hamano | a476efa | 2008-10-10 15:31:42 | [diff] [blame] | 180 | |
Junio C Hamano | b9d9d90 | 2018-05-23 07:07:42 | [diff] [blame] | 181 | This hook is called by linkgit:git-rebase[1] and can be used to prevent a |
Junio C Hamano | 947ab82 | 2013-03-19 23:07:29 | [diff] [blame] | 182 | branch from getting rebased. The hook may be called with one or |
| 183 | two parameters. The first parameter is the upstream from which |
| 184 | the series was forked. The second parameter is the branch being |
| 185 | rebased, and is not set when rebasing the current branch. |
Junio C Hamano | a476efa | 2008-10-10 15:31:42 | [diff] [blame] | 186 | |
Junio C Hamano | 1b50ce9 | 2007-10-03 12:05:53 | [diff] [blame] | 187 | post-checkout |
Junio C Hamano | c28068f | 2009-09-08 00:55:23 | [diff] [blame] | 188 | ~~~~~~~~~~~~~ |
Junio C Hamano | 1b50ce9 | 2007-10-03 12:05:53 | [diff] [blame] | 189 | |
Junio C Hamano | c9f11c2 | 2019-07-10 02:54:04 | [diff] [blame] | 190 | This hook is invoked when a linkgit:git-checkout[1] or |
| 191 | linkgit:git-switch[1] is run after having updated the |
Junio C Hamano | 1b50ce9 | 2007-10-03 12:05:53 | [diff] [blame] | 192 | worktree. The hook is given three parameters: the ref of the previous HEAD, |
| 193 | the ref of the new HEAD (which may or may not have changed), and a flag |
| 194 | indicating whether the checkout was a branch checkout (changing branches, |
| 195 | flag=1) or a file checkout (retrieving a file from the index, flag=0). |
Junio C Hamano | c9f11c2 | 2019-07-10 02:54:04 | [diff] [blame] | 196 | This hook cannot affect the outcome of `git switch` or `git checkout`. |
Junio C Hamano | 1b50ce9 | 2007-10-03 12:05:53 | [diff] [blame] | 197 | |
Junio C Hamano | b9d9d90 | 2018-05-23 07:07:42 | [diff] [blame] | 198 | It is also run after linkgit:git-clone[1], unless the `--no-checkout` (`-n`) option is |
Junio C Hamano | 36a5672 | 2009-03-28 08:55:34 | [diff] [blame] | 199 | used. The first parameter given to the hook is the null-ref, the second the |
Junio C Hamano | b9d9d90 | 2018-05-23 07:07:42 | [diff] [blame] | 200 | ref of the new HEAD and the flag is always 1. Likewise for `git worktree add` |
| 201 | unless `--no-checkout` is used. |
Junio C Hamano | 36a5672 | 2009-03-28 08:55:34 | [diff] [blame] | 202 | |
Junio C Hamano | 1b50ce9 | 2007-10-03 12:05:53 | [diff] [blame] | 203 | This hook can be used to perform repository validity checks, auto-display |
| 204 | differences from the previous HEAD if different, or set working dir metadata |
| 205 | properties. |
| 206 | |
Junio C Hamano | 01d8f83 | 2007-09-24 07:37:30 | [diff] [blame] | 207 | post-merge |
Junio C Hamano | c28068f | 2009-09-08 00:55:23 | [diff] [blame] | 208 | ~~~~~~~~~~ |
Junio C Hamano | 01d8f83 | 2007-09-24 07:37:30 | [diff] [blame] | 209 | |
Junio C Hamano | b9d9d90 | 2018-05-23 07:07:42 | [diff] [blame] | 210 | This hook is invoked by linkgit:git-merge[1], which happens when a `git pull` |
Junio C Hamano | 01d8f83 | 2007-09-24 07:37:30 | [diff] [blame] | 211 | is done on a local repository. The hook takes a single parameter, a status |
| 212 | flag specifying whether or not the merge being done was a squash merge. |
Junio C Hamano | b9d9d90 | 2018-05-23 07:07:42 | [diff] [blame] | 213 | This hook cannot affect the outcome of `git merge` and is not executed, |
Junio C Hamano | 47d68a5 | 2008-05-06 06:35:40 | [diff] [blame] | 214 | if the merge failed due to conflicts. |
Junio C Hamano | 01d8f83 | 2007-09-24 07:37:30 | [diff] [blame] | 215 | |
| 216 | This hook can be used in conjunction with a corresponding pre-commit hook to |
| 217 | save and restore any form of metadata associated with the working tree |
Junio C Hamano | fb5ffde | 2014-11-04 22:38:56 | [diff] [blame] | 218 | (e.g.: permissions/ownership, ACLS, etc). See contrib/hooks/setgitperms.perl |
Junio C Hamano | 01d8f83 | 2007-09-24 07:37:30 | [diff] [blame] | 219 | for an example of how to do this. |
| 220 | |
Junio C Hamano | 36d5229 | 2013-01-25 21:32:36 | [diff] [blame] | 221 | pre-push |
| 222 | ~~~~~~~~ |
| 223 | |
Junio C Hamano | b9d9d90 | 2018-05-23 07:07:42 | [diff] [blame] | 224 | This hook is called by linkgit:git-push[1] and can be used to prevent |
| 225 | a push from taking place. The hook is called with two parameters |
| 226 | which provide the name and location of the destination remote, if a |
| 227 | named remote is not being used both values will be the same. |
Junio C Hamano | 36d5229 | 2013-01-25 21:32:36 | [diff] [blame] | 228 | |
| 229 | Information about what is to be pushed is provided on the hook's standard |
| 230 | input with lines of the form: |
| 231 | |
| 232 | <local ref> SP <local sha1> SP <remote ref> SP <remote sha1> LF |
| 233 | |
| 234 | For instance, if the command +git push origin master:foreign+ were run the |
| 235 | hook would receive a line like the following: |
| 236 | |
| 237 | refs/heads/master 67890 refs/heads/foreign 12345 |
| 238 | |
Junio C Hamano | e3f080d | 2013-04-22 02:27:13 | [diff] [blame] | 239 | although the full, 40-character SHA-1s would be supplied. If the foreign ref |
| 240 | does not yet exist the `<remote SHA-1>` will be 40 `0`. If a ref is to be |
Junio C Hamano | 36d5229 | 2013-01-25 21:32:36 | [diff] [blame] | 241 | deleted, the `<local ref>` will be supplied as `(delete)` and the `<local |
Junio C Hamano | e3f080d | 2013-04-22 02:27:13 | [diff] [blame] | 242 | SHA-1>` will be 40 `0`. If the local commit was specified by something other |
| 243 | than a name which could be expanded (such as `HEAD~`, or a SHA-1) it will be |
Junio C Hamano | 36d5229 | 2013-01-25 21:32:36 | [diff] [blame] | 244 | supplied as it was originally given. |
| 245 | |
Junio C Hamano | b9d9d90 | 2018-05-23 07:07:42 | [diff] [blame] | 246 | If this hook exits with a non-zero status, `git push` will abort without |
Junio C Hamano | 36d5229 | 2013-01-25 21:32:36 | [diff] [blame] | 247 | pushing anything. Information about why the push is rejected may be sent |
| 248 | to the user by writing to standard error. |
| 249 | |
Junio C Hamano | 8638c92 | 2007-05-12 20:50:08 | [diff] [blame] | 250 | [[pre-receive]] |
| 251 | pre-receive |
Junio C Hamano | c28068f | 2009-09-08 00:55:23 | [diff] [blame] | 252 | ~~~~~~~~~~~ |
Junio C Hamano | 8638c92 | 2007-05-12 20:50:08 | [diff] [blame] | 253 | |
Junio C Hamano | b9d9d90 | 2018-05-23 07:07:42 | [diff] [blame] | 254 | This hook is invoked by linkgit:git-receive-pack[1] when it reacts to |
| 255 | `git push` and updates reference(s) in its repository. |
Junio C Hamano | 8638c92 | 2007-05-12 20:50:08 | [diff] [blame] | 256 | Just before starting to update refs on the remote repository, the |
| 257 | pre-receive hook is invoked. Its exit status determines the success |
| 258 | or failure of the update. |
| 259 | |
| 260 | This hook executes once for the receive operation. It takes no |
| 261 | arguments, but for each ref to be updated it receives on standard |
| 262 | input a line of the format: |
| 263 | |
| 264 | <old-value> SP <new-value> SP <ref-name> LF |
| 265 | |
| 266 | where `<old-value>` is the old object name stored in the ref, |
| 267 | `<new-value>` is the new object name to be stored in the ref and |
| 268 | `<ref-name>` is the full name of the ref. |
| 269 | When creating a new ref, `<old-value>` is 40 `0`. |
| 270 | |
| 271 | If the hook exits with non-zero status, none of the refs will be |
| 272 | updated. If the hook exits with zero, updating of individual refs can |
| 273 | still be prevented by the <<update,'update'>> hook. |
| 274 | |
Junio C Hamano | 323e52d | 2007-05-13 22:19:53 | [diff] [blame] | 275 | Both standard output and standard error output are forwarded to |
Junio C Hamano | b9d9d90 | 2018-05-23 07:07:42 | [diff] [blame] | 276 | `git send-pack` on the other end, so you can simply `echo` messages |
Junio C Hamano | 323e52d | 2007-05-13 22:19:53 | [diff] [blame] | 277 | for the user. |
Junio C Hamano | 8638c92 | 2007-05-12 20:50:08 | [diff] [blame] | 278 | |
Junio C Hamano | e48a113 | 2016-08-03 22:40:21 | [diff] [blame] | 279 | The number of push options given on the command line of |
| 280 | `git push --push-option=...` can be read from the environment |
| 281 | variable `GIT_PUSH_OPTION_COUNT`, and the options themselves are |
| 282 | found in `GIT_PUSH_OPTION_0`, `GIT_PUSH_OPTION_1`,... |
| 283 | If it is negotiated to not use the push options phase, the |
| 284 | environment variables will not be set. If the client selects |
| 285 | to use push options, but doesn't transmit any, the count variable |
| 286 | will be set to zero, `GIT_PUSH_OPTION_COUNT=0`. |
| 287 | |
Junio C Hamano | e25cc81 | 2017-04-24 06:17:43 | [diff] [blame] | 288 | See the section on "Quarantine Environment" in |
| 289 | linkgit:git-receive-pack[1] for some caveats. |
| 290 | |
Junio C Hamano | 8638c92 | 2007-05-12 20:50:08 | [diff] [blame] | 291 | [[update]] |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 292 | update |
Junio C Hamano | c28068f | 2009-09-08 00:55:23 | [diff] [blame] | 293 | ~~~~~~ |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 294 | |
Junio C Hamano | b9d9d90 | 2018-05-23 07:07:42 | [diff] [blame] | 295 | This hook is invoked by linkgit:git-receive-pack[1] when it reacts to |
| 296 | `git push` and updates reference(s) in its repository. |
Junio C Hamano | 818f7d6 | 2006-03-26 01:49:30 | [diff] [blame] | 297 | Just before updating the ref on the remote repository, the update hook |
Junio C Hamano | 33db437 | 2006-06-07 19:51:45 | [diff] [blame] | 298 | is invoked. Its exit status determines the success or failure of |
Junio C Hamano | 818f7d6 | 2006-03-26 01:49:30 | [diff] [blame] | 299 | the ref update. |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 300 | |
Junio C Hamano | 818f7d6 | 2006-03-26 01:49:30 | [diff] [blame] | 301 | The hook executes once for each ref to be updated, and takes |
| 302 | three parameters: |
Junio C Hamano | d578413 | 2006-09-20 21:29:27 | [diff] [blame] | 303 | |
| 304 | - the name of the ref being updated, |
| 305 | - the old object name stored in the ref, |
Junio C Hamano | 826f5c4 | 2014-02-07 20:33:30 | [diff] [blame] | 306 | - and the new object name to be stored in the ref. |
Junio C Hamano | 818f7d6 | 2006-03-26 01:49:30 | [diff] [blame] | 307 | |
| 308 | A zero exit from the update hook allows the ref to be updated. |
Junio C Hamano | b9d9d90 | 2018-05-23 07:07:42 | [diff] [blame] | 309 | Exiting with a non-zero status prevents `git receive-pack` |
Junio C Hamano | 8638c92 | 2007-05-12 20:50:08 | [diff] [blame] | 310 | from updating that ref. |
Junio C Hamano | 818f7d6 | 2006-03-26 01:49:30 | [diff] [blame] | 311 | |
| 312 | This hook can be used to prevent 'forced' update on certain refs by |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 313 | making sure that the object name is a commit object that is a |
| 314 | descendant of the commit object named by the old object name. |
Junio C Hamano | 3f680f3 | 2009-11-16 02:10:54 | [diff] [blame] | 315 | That is, to enforce a "fast-forward only" policy. |
Junio C Hamano | 818f7d6 | 2006-03-26 01:49:30 | [diff] [blame] | 316 | |
| 317 | It could also be used to log the old..new status. However, it |
| 318 | does not know the entire set of branches, so it would end up |
Junio C Hamano | 8638c92 | 2007-05-12 20:50:08 | [diff] [blame] | 319 | firing one e-mail per ref when used naively, though. The |
| 320 | <<post-receive,'post-receive'>> hook is more suited to that. |
Junio C Hamano | 818f7d6 | 2006-03-26 01:49:30 | [diff] [blame] | 321 | |
Junio C Hamano | 198b1f1 | 2016-05-17 22:27:24 | [diff] [blame] | 322 | In an environment that restricts the users' access only to git |
| 323 | commands over the wire, this hook can be used to implement access |
| 324 | control without relying on filesystem ownership and group |
| 325 | membership. See linkgit:git-shell[1] for how you might use the login |
| 326 | shell to restrict the user's access to only git commands. |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 327 | |
Junio C Hamano | 323e52d | 2007-05-13 22:19:53 | [diff] [blame] | 328 | Both standard output and standard error output are forwarded to |
Junio C Hamano | b9d9d90 | 2018-05-23 07:07:42 | [diff] [blame] | 329 | `git send-pack` on the other end, so you can simply `echo` messages |
Junio C Hamano | 323e52d | 2007-05-13 22:19:53 | [diff] [blame] | 330 | for the user. |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 331 | |
Junio C Hamano | 8638c92 | 2007-05-12 20:50:08 | [diff] [blame] | 332 | The default 'update' hook, when enabled--and with |
Junio C Hamano | d6fff40 | 2009-09-14 09:40:50 | [diff] [blame] | 333 | `hooks.allowunannotated` config option unset or set to false--prevents |
Junio C Hamano | 8638c92 | 2007-05-12 20:50:08 | [diff] [blame] | 334 | unannotated tags to be pushed. |
Junio C Hamano | 818f7d6 | 2006-03-26 01:49:30 | [diff] [blame] | 335 | |
Junio C Hamano | 8638c92 | 2007-05-12 20:50:08 | [diff] [blame] | 336 | [[post-receive]] |
| 337 | post-receive |
Junio C Hamano | c28068f | 2009-09-08 00:55:23 | [diff] [blame] | 338 | ~~~~~~~~~~~~ |
Junio C Hamano | 8638c92 | 2007-05-12 20:50:08 | [diff] [blame] | 339 | |
Junio C Hamano | b9d9d90 | 2018-05-23 07:07:42 | [diff] [blame] | 340 | This hook is invoked by linkgit:git-receive-pack[1] when it reacts to |
| 341 | `git push` and updates reference(s) in its repository. |
Junio C Hamano | 8638c92 | 2007-05-12 20:50:08 | [diff] [blame] | 342 | It executes on the remote repository once after all the refs have |
| 343 | been updated. |
| 344 | |
| 345 | This hook executes once for the receive operation. It takes no |
Junio C Hamano | 323e52d | 2007-05-13 22:19:53 | [diff] [blame] | 346 | arguments, but gets the same information as the |
| 347 | <<pre-receive,'pre-receive'>> |
Junio C Hamano | 8638c92 | 2007-05-12 20:50:08 | [diff] [blame] | 348 | hook does on its standard input. |
| 349 | |
Junio C Hamano | b9d9d90 | 2018-05-23 07:07:42 | [diff] [blame] | 350 | This hook does not affect the outcome of `git receive-pack`, as it |
Junio C Hamano | 8638c92 | 2007-05-12 20:50:08 | [diff] [blame] | 351 | is called after the real work is done. |
| 352 | |
Junio C Hamano | a638742 | 2007-08-25 03:54:27 | [diff] [blame] | 353 | This supersedes the <<post-update,'post-update'>> hook in that it gets |
Junio C Hamano | 323e52d | 2007-05-13 22:19:53 | [diff] [blame] | 354 | both old and new values of all the refs in addition to their |
| 355 | names. |
Junio C Hamano | 8638c92 | 2007-05-12 20:50:08 | [diff] [blame] | 356 | |
Junio C Hamano | 323e52d | 2007-05-13 22:19:53 | [diff] [blame] | 357 | Both standard output and standard error output are forwarded to |
Junio C Hamano | b9d9d90 | 2018-05-23 07:07:42 | [diff] [blame] | 358 | `git send-pack` on the other end, so you can simply `echo` messages |
Junio C Hamano | 323e52d | 2007-05-13 22:19:53 | [diff] [blame] | 359 | for the user. |
Junio C Hamano | 8638c92 | 2007-05-12 20:50:08 | [diff] [blame] | 360 | |
| 361 | The default 'post-receive' hook is empty, but there is |
| 362 | a sample script `post-receive-email` provided in the `contrib/hooks` |
Junio C Hamano | 076ffcc | 2013-02-06 05:13:21 | [diff] [blame] | 363 | directory in Git distribution, which implements sending commit |
Junio C Hamano | 8638c92 | 2007-05-12 20:50:08 | [diff] [blame] | 364 | emails. |
| 365 | |
Junio C Hamano | e48a113 | 2016-08-03 22:40:21 | [diff] [blame] | 366 | The number of push options given on the command line of |
| 367 | `git push --push-option=...` can be read from the environment |
| 368 | variable `GIT_PUSH_OPTION_COUNT`, and the options themselves are |
| 369 | found in `GIT_PUSH_OPTION_0`, `GIT_PUSH_OPTION_1`,... |
| 370 | If it is negotiated to not use the push options phase, the |
| 371 | environment variables will not be set. If the client selects |
| 372 | to use push options, but doesn't transmit any, the count variable |
| 373 | will be set to zero, `GIT_PUSH_OPTION_COUNT=0`. |
| 374 | |
Junio C Hamano | 8638c92 | 2007-05-12 20:50:08 | [diff] [blame] | 375 | [[post-update]] |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 376 | post-update |
Junio C Hamano | c28068f | 2009-09-08 00:55:23 | [diff] [blame] | 377 | ~~~~~~~~~~~ |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 378 | |
Junio C Hamano | b9d9d90 | 2018-05-23 07:07:42 | [diff] [blame] | 379 | This hook is invoked by linkgit:git-receive-pack[1] when it reacts to |
| 380 | `git push` and updates reference(s) in its repository. |
Junio C Hamano | 818f7d6 | 2006-03-26 01:49:30 | [diff] [blame] | 381 | It executes on the remote repository once after all the refs have |
| 382 | been updated. |
| 383 | |
| 384 | It takes a variable number of parameters, each of which is the |
| 385 | name of ref that was actually updated. |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 386 | |
| 387 | This hook is meant primarily for notification, and cannot affect |
Junio C Hamano | b9d9d90 | 2018-05-23 07:07:42 | [diff] [blame] | 388 | the outcome of `git receive-pack`. |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 389 | |
Junio C Hamano | d578413 | 2006-09-20 21:29:27 | [diff] [blame] | 390 | The 'post-update' hook can tell what are the heads that were pushed, |
Junio C Hamano | 818f7d6 | 2006-03-26 01:49:30 | [diff] [blame] | 391 | but it does not know what their original and updated values are, |
Junio C Hamano | 323e52d | 2007-05-13 22:19:53 | [diff] [blame] | 392 | so it is a poor place to do log old..new. The |
| 393 | <<post-receive,'post-receive'>> hook does get both original and |
| 394 | updated values of the refs. You might consider it instead if you need |
| 395 | them. |
Junio C Hamano | 8638c92 | 2007-05-12 20:50:08 | [diff] [blame] | 396 | |
Junio C Hamano | d578413 | 2006-09-20 21:29:27 | [diff] [blame] | 397 | When enabled, the default 'post-update' hook runs |
Junio C Hamano | b9d9d90 | 2018-05-23 07:07:42 | [diff] [blame] | 398 | `git update-server-info` to keep the information used by dumb |
Junio C Hamano | 88bf571 | 2017-09-10 08:39:23 | [diff] [blame] | 399 | transports (e.g., HTTP) up to date. If you are publishing |
Junio C Hamano | 076ffcc | 2013-02-06 05:13:21 | [diff] [blame] | 400 | a Git repository that is accessible via HTTP, you should |
Junio C Hamano | 818f7d6 | 2006-03-26 01:49:30 | [diff] [blame] | 401 | probably enable this hook. |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 402 | |
Junio C Hamano | 8638c92 | 2007-05-12 20:50:08 | [diff] [blame] | 403 | Both standard output and standard error output are forwarded to |
Junio C Hamano | b9d9d90 | 2018-05-23 07:07:42 | [diff] [blame] | 404 | `git send-pack` on the other end, so you can simply `echo` messages |
Junio C Hamano | 323e52d | 2007-05-13 22:19:53 | [diff] [blame] | 405 | for the user. |
Junio C Hamano | e3ddb5b | 2008-04-21 00:48:07 | [diff] [blame] | 406 | |
Junio C Hamano | 6bb32e6 | 2015-02-17 22:11:26 | [diff] [blame] | 407 | push-to-checkout |
| 408 | ~~~~~~~~~~~~~~~~ |
| 409 | |
Junio C Hamano | b9d9d90 | 2018-05-23 07:07:42 | [diff] [blame] | 410 | This hook is invoked by linkgit:git-receive-pack[1] when it reacts to |
| 411 | `git push` and updates reference(s) in its repository, and when |
Junio C Hamano | 6bb32e6 | 2015-02-17 22:11:26 | [diff] [blame] | 412 | the push tries to update the branch that is currently checked out |
| 413 | and the `receive.denyCurrentBranch` configuration variable is set to |
| 414 | `updateInstead`. Such a push by default is refused if the working |
| 415 | tree and the index of the remote repository has any difference from |
| 416 | the currently checked out commit; when both the working tree and the |
| 417 | index match the current commit, they are updated to match the newly |
| 418 | pushed tip of the branch. This hook is to be used to override the |
| 419 | default behaviour. |
| 420 | |
| 421 | The hook receives the commit with which the tip of the current |
| 422 | branch is going to be updated. It can exit with a non-zero status |
| 423 | to refuse the push (when it does so, it must not modify the index or |
| 424 | the working tree). Or it can make any necessary changes to the |
| 425 | working tree and to the index to bring them to the desired state |
| 426 | when the tip of the current branch is updated to the new commit, and |
| 427 | exit with a zero status. |
| 428 | |
| 429 | For example, the hook can simply run `git read-tree -u -m HEAD "$1"` |
Junio C Hamano | b9d9d90 | 2018-05-23 07:07:42 | [diff] [blame] | 430 | in order to emulate `git fetch` that is run in the reverse direction |
| 431 | with `git push`, as the two-tree form of `git read-tree -u -m` is |
Junio C Hamano | c9f11c2 | 2019-07-10 02:54:04 | [diff] [blame] | 432 | essentially the same as `git switch` or `git checkout` |
| 433 | that switches branches while |
Junio C Hamano | 6bb32e6 | 2015-02-17 22:11:26 | [diff] [blame] | 434 | keeping the local changes in the working tree that do not interfere |
| 435 | with the difference between the branches. |
| 436 | |
| 437 | |
Junio C Hamano | e3ddb5b | 2008-04-21 00:48:07 | [diff] [blame] | 438 | pre-auto-gc |
Junio C Hamano | c28068f | 2009-09-08 00:55:23 | [diff] [blame] | 439 | ~~~~~~~~~~~ |
Junio C Hamano | e3ddb5b | 2008-04-21 00:48:07 | [diff] [blame] | 440 | |
Junio C Hamano | b9d9d90 | 2018-05-23 07:07:42 | [diff] [blame] | 441 | This hook is invoked by `git gc --auto` (see linkgit:git-gc[1]). It |
| 442 | takes no parameter, and exiting with non-zero status from this script |
| 443 | causes the `git gc --auto` to abort. |
Junio C Hamano | 2fbcd21 | 2008-05-14 22:26:07 | [diff] [blame] | 444 | |
Junio C Hamano | 3166736 | 2010-03-25 00:38:53 | [diff] [blame] | 445 | post-rewrite |
| 446 | ~~~~~~~~~~~~ |
| 447 | |
Junio C Hamano | b9d9d90 | 2018-05-23 07:07:42 | [diff] [blame] | 448 | This hook is invoked by commands that rewrite commits |
| 449 | (linkgit:git-commit[1] when called with `--amend` and |
Junio C Hamano | a885831 | 2019-09-30 05:07:45 | [diff] [blame^] | 450 | linkgit:git-rebase[1]; however, full-history (re)writing tools like |
| 451 | linkgit:git-fast-import[1] or |
| 452 | https://github.com/newren/git-filter-repo[git-filter-repo] typically |
| 453 | do not call it!). Its first argument denotes the command it was |
| 454 | invoked by: currently one of `amend` or `rebase`. Further |
| 455 | command-dependent arguments may be passed in the future. |
Junio C Hamano | 3166736 | 2010-03-25 00:38:53 | [diff] [blame] | 456 | |
| 457 | The hook receives a list of the rewritten commits on stdin, in the |
| 458 | format |
| 459 | |
| 460 | <old-sha1> SP <new-sha1> [ SP <extra-info> ] LF |
| 461 | |
| 462 | The 'extra-info' is again command-dependent. If it is empty, the |
| 463 | preceding SP is also omitted. Currently, no commands pass any |
| 464 | 'extra-info'. |
| 465 | |
| 466 | The hook always runs after the automatic note copying (see |
Junio C Hamano | 96fdfa1 | 2016-03-21 20:52:39 | [diff] [blame] | 467 | "notes.rewrite.<command>" in linkgit:git-config[1]) has happened, and |
Junio C Hamano | 3166736 | 2010-03-25 00:38:53 | [diff] [blame] | 468 | thus has access to these notes. |
| 469 | |
| 470 | The following command-specific comments apply: |
| 471 | |
| 472 | rebase:: |
| 473 | For the 'squash' and 'fixup' operation, all commits that were |
| 474 | squashed are listed as being rewritten to the squashed commit. |
| 475 | This means that there will be several lines sharing the same |
| 476 | 'new-sha1'. |
| 477 | + |
| 478 | The commits are guaranteed to be listed in the order that they were |
| 479 | processed by rebase. |
| 480 | |
Junio C Hamano | d88ba73 | 2017-05-30 04:14:20 | [diff] [blame] | 481 | sendemail-validate |
| 482 | ~~~~~~~~~~~~~~~~~~ |
| 483 | |
Junio C Hamano | b9d9d90 | 2018-05-23 07:07:42 | [diff] [blame] | 484 | This hook is invoked by linkgit:git-send-email[1]. It takes a single parameter, |
Junio C Hamano | d88ba73 | 2017-05-30 04:14:20 | [diff] [blame] | 485 | the name of the file that holds the e-mail to be sent. Exiting with a |
Junio C Hamano | b9d9d90 | 2018-05-23 07:07:42 | [diff] [blame] | 486 | non-zero status causes `git send-email` to abort before sending any |
Junio C Hamano | d88ba73 | 2017-05-30 04:14:20 | [diff] [blame] | 487 | e-mails. |
| 488 | |
Junio C Hamano | d710560 | 2017-11-21 05:32:50 | [diff] [blame] | 489 | fsmonitor-watchman |
| 490 | ~~~~~~~~~~~~~~~~~~ |
| 491 | |
Junio C Hamano | b9d9d90 | 2018-05-23 07:07:42 | [diff] [blame] | 492 | This hook is invoked when the configuration option `core.fsmonitor` is |
| 493 | set to `.git/hooks/fsmonitor-watchman`. It takes two arguments, a version |
Junio C Hamano | d710560 | 2017-11-21 05:32:50 | [diff] [blame] | 494 | (currently 1) and the time in elapsed nanoseconds since midnight, |
| 495 | January 1, 1970. |
| 496 | |
| 497 | The hook should output to stdout the list of all files in the working |
| 498 | directory that may have changed since the requested time. The logic |
| 499 | should be inclusive so that it does not miss any potential changes. |
| 500 | The paths should be relative to the root of the working directory |
| 501 | and be separated by a single NUL. |
| 502 | |
| 503 | It is OK to include files which have not actually changed. All changes |
| 504 | including newly-created and deleted files should be included. When |
| 505 | files are renamed, both the old and the new name should be included. |
| 506 | |
| 507 | Git will limit what files it checks for changes as well as which |
| 508 | directories are checked for untracked files based on the path names |
| 509 | given. |
| 510 | |
| 511 | An optimized way to tell git "all files have changed" is to return |
Junio C Hamano | b9d9d90 | 2018-05-23 07:07:42 | [diff] [blame] | 512 | the filename `/`. |
Junio C Hamano | d710560 | 2017-11-21 05:32:50 | [diff] [blame] | 513 | |
| 514 | The exit status determines whether git will use the data from the |
| 515 | hook to limit its search. On error, it will fall back to verifying |
| 516 | all files and folders. |
Junio C Hamano | 3166736 | 2010-03-25 00:38:53 | [diff] [blame] | 517 | |
Junio C Hamano | bfd91f4 | 2018-08-17 22:21:16 | [diff] [blame] | 518 | p4-pre-submit |
| 519 | ~~~~~~~~~~~~~ |
| 520 | |
| 521 | This hook is invoked by `git-p4 submit`. It takes no parameters and nothing |
| 522 | from standard input. Exiting with non-zero status from this script prevent |
| 523 | `git-p4 submit` from launching. Run `git-p4 submit --help` for details. |
| 524 | |
Junio C Hamano | 2ba1471 | 2019-04-25 10:12:27 | [diff] [blame] | 525 | post-index-change |
| 526 | ~~~~~~~~~~~~~~~~~ |
| 527 | |
| 528 | This hook is invoked when the index is written in read-cache.c |
| 529 | do_write_locked_index. |
| 530 | |
| 531 | The first parameter passed to the hook is the indicator for the |
| 532 | working directory being updated. "1" meaning working directory |
| 533 | was updated or "0" when the working directory was not updated. |
| 534 | |
| 535 | The second parameter passed to the hook is the indicator for whether |
| 536 | or not the index was updated and the skip-worktree bit could have |
| 537 | changed. "1" meaning skip-worktree bits could have been updated |
| 538 | and "0" meaning they were not. |
| 539 | |
| 540 | Only one parameter should be set to "1" when the hook runs. The hook |
| 541 | running passing "1", "1" should not be possible. |
| 542 | |
Junio C Hamano | 2fbcd21 | 2008-05-14 22:26:07 | [diff] [blame] | 543 | GIT |
| 544 | --- |
Junio C Hamano | f7c042d | 2008-06-06 22:50:53 | [diff] [blame] | 545 | Part of the linkgit:git[1] suite |