---
title: "Commit Hooks"
manual: "TYPO3 Core Contribution Guide"
version: "main"
permalink: "https://docs.typo3.org/permalink/t3contribute:commit-hook"
source: "Appendix/CommitHook.rst"
rendered: "2026-10-05T15:34:44+00:00"
---

# Commit Hooks {#commit-hook}

## `commit-msg` Hook {#commit-msg-hook}

-   File: `.git/hooks/commit-msg`
-   Source file: `Build/git-hooks/commit-msg`

This hook is mandatory. It **must** be used for core contribution!

First of all, this hook will be executed whenever you do a commit on your local machine.

The most important task of the hook is to generate a unique `Change-Id` for your
commit. This Change-Id is **mandatory** for [Gerrit](https://review.typo3.org) to identify your change.
There is no way around this and it is not up for discussion :) This Change-Id
will only be generated if it is not yet present in your commit message - please
do not try to come up with a Change-Id on your own, the result will be chaos.

Apart from that the hook will check your commit message for logical errors like
missing keywords, Resolves lines etc. For detailed information on the format of
a commit message, [click here](https://docs.typo3.org/permalink/t3contribute:commitmessage). This also describes cases
in which you might exceed the line length of 72 characters (hyperlinks).

If the commit-msg hook finds errors in your commit-msg, you can try again, by
amending to the commit:

```
git commit --amend

```

## `pre-commit` Hook {#pre-commit-hook}

-   File: `.git/hooks/pre-commit`
-   Source file: `Build/git-hooks/unix+mac/pre-commit`
-   This hook is optional. **This hook is not available for Windows.**, however
    it can be executed on Windows machines by using a tool like
    the [Git BASH](https://gitforwindows.org/).

The `pre-commit` hook checks all added PHP files staged for the commit for Coding
Guideline issues and will report any problems it finds.

To fix the issues, see [CGL check and fix](https://docs.typo3.org/permalink/t3contribute:cgl-fix-my-commit).

After fixing the files you must amend your commit:

```bash
git commit -a --amend
```

## Post-checkout hook for composer install {#post-checkout-for-composer-update}

If you want to run `composer install` for each checkout (e.g. when switching
branches, tags, etc), then you can use the `post-checkout` commit hook.

Create a file named `.git/hooks/post-checkout` with the following contents:

```bash
#!/usr/bin/env python3
#-*- coding: utf-8 -*-

"""A post-checkout git hook to execute `composer install`

:Author: Philipp Gampe
"""

import subprocess
import string
import os
import sys

PATH_TO_COMPOSER = '/home/phil/bin/composer.phar'
HOOK_DIR = os.path.dirname(os.path.realpath(__file__))
GIT_ROOT_DIR = os.path.dirname(os.path.dirname(HOOK_DIR))

def main():
    if sys.argv[3] == '1':
        os.chdir(GIT_ROOT_DIR)
        return subprocess.run([PATH_TO_COMPOSER, 'install'], timeout=30)

if __name__ == '__main__':
    result = main()
    if result:
        exit(result.returncode)
    else:
        exit(0)
```

> [!IMPORTANT]
> You need to adjust the `PATH_TO_COMPOSER` variable, that is defined after the import statements.
> Additionally the `python3` executable needs to be available in your `PATH`.
