Git server hooks are scripts that Gitaly runs on the server when a push changes the repository. A pre-receive hook that exits with a non-zero code rejects the whole push; an update hook rejects a single branch or tag. Server hooks are set up by an instance administrator with access to the Gitaly servers; they have no settings in the web interface.

Hook types and run order

Gitaly runs the hooks pre-receive, update and post-receive with the arguments and the standard input that Git passes to them. For each hook, Gitaly runs in this order:

  1. The project hook custom_hooks/<hook> in the repository directory.
  2. The project hooks custom_hooks/<hook>.d/* in the repository directory, sorted by file name.
  3. The instance hooks <hook>.d/* in the instance hooks directory, sorted by file name.

Gitaly skips files that are not executable and files whose names end with ~. The first hook that exits with a non-zero code stops the chain. Every hook runs in the repository directory and receives these environment variables:

VariableValue
GL_IDID of the user who pushed, in the user-<ID> form.
GL_USERNAMEUsername of the user who pushed.
GL_PROJECT_PATHFull path of the project, for example group/project.
GL_REPOSITORYRepository identifier, for example project-<PROJECT_ID>.
GL_PROTOCOLProtocol of the push: http, ssh or web.
GIT_PUSH_OPTION_COUNT, GIT_PUSH_OPTION_<N>Push options passed with git push -o.

Error messages

The output of a hook that rejected a push is shown to the user in the git push output. When the change is made in the web interface (a merge, a commit from the editor), the web interface shows the text of the message when the hook starts it with the GL-HOOK-ERR: prefix:

#!/bin/sh
echo "GL-HOOK-ERR: Commits to this repository must reference an issue."
exit 1

Instance hooks

Instance hooks run for every repository of the Gitaly server. Place each hook in the directory named after it: pre-receive.d, update.d or post-receive.d.

  • Linux package
  • Omnibus Docker
  • Helm Chart
  1. Set the instance hooks directory in /etc/gitlab/gitlab.rb:

    gitaly['configuration'] = {
      hooks: {
        custom_hooks_dir: '/var/opt/gitlab/gitaly/custom_hooks',
      },
    }

    If gitaly['configuration'] is already set, add the hooks key to the existing hash.

  2. Apply the change:

    sudo gitlab-ctl reconfigure
  3. Create the directory of the hook and copy the script into it:

    sudo mkdir -p /var/opt/gitlab/gitaly/custom_hooks/pre-receive.d
    sudo cp check-commit-message.sh /var/opt/gitlab/gitaly/custom_hooks/pre-receive.d/
  4. Make the script executable and give it to the git user:

    sudo chown -R git:git /var/opt/gitlab/gitaly/custom_hooks
    sudo chmod 755 /var/opt/gitlab/gitaly/custom_hooks/pre-receive.d/check-commit-message.sh

Gitaly picks up a new or changed script on the next push.

  1. Set the instance hooks directory in /srv/code/config/gitlab.rb on the host:

    gitaly['configuration'] = {
      hooks: {
        custom_hooks_dir: '/var/opt/gitlab/gitaly/custom_hooks',
      },
    }

    If gitaly['configuration'] is already set, add the hooks key to the existing hash.

  2. Apply the change:

    docker exec code gitlab-ctl reconfigure
  3. Create the directory of the hook and copy the script into it. The /var/opt/gitlab directory of the container is /srv/code/data on the host:

    sudo mkdir -p /srv/code/data/gitaly/custom_hooks/pre-receive.d
    sudo cp check-commit-message.sh /srv/code/data/gitaly/custom_hooks/pre-receive.d/
  4. Make the script executable and give it to the git user of the container:

    docker exec code chown -R git:git /var/opt/gitlab/gitaly/custom_hooks
    docker exec code chmod 755 /var/opt/gitlab/gitaly/custom_hooks/pre-receive.d/check-commit-message.sh

Gitaly picks up a new or changed script on the next push.

  1. Create a ConfigMap with the scripts in the release namespace. Each key of the ConfigMap becomes a file in the hook directory:

    d8 k -n code create configmap gitaly-pre-receive-hooks --from-file=check-commit-message.sh
  2. Name the ConfigMap in values.yaml:

    global:
      gitaly:
        hooks:
          preReceive:
            configmap: gitaly-pre-receive-hooks

    The update and post-receive hooks take the update.configmap and postReceive.configmap keys.

  3. Apply the values to the release:

    helm upgrade code oci://<CHART_REGISTRY>/code \
      --version <CHART_VERSION> \
      -n code \
      -f values.yaml

The chart mounts the ConfigMap into /home/git/custom_hooks/pre-receive.d of the Gitaly pods with the mode 0555.

Project hooks

Project hooks run only for the repository of one project. They are written to the custom_hooks directory of the repository with the gitaly hooks set command, which reads a tar archive from the standard input. With Praefect, the command is run on every Gitaly server that holds a replica of the repository.

  1. Find the storage name and the path of the repository as described in Repository path on the storage. With Praefect, take the replica path and the storages of the replicas from the praefect metadata output.

  2. Put the scripts into a local custom_hooks directory: a single hook as custom_hooks/pre-receive, several hooks as files in custom_hooks/pre-receive.d/. Make them executable:

    chmod 755 custom_hooks/pre-receive
  3. Pack the directory into an archive. The archive must contain the custom_hooks directory itself:

    tar -cf custom_hooks.tar custom_hooks

Load the archive into the repository with the command of your installation type.

  • Linux package
  • Omnibus Docker
  • Helm Chart
  • Deckhouse Platform module

<STORAGE_NAME> and <RELATIVE_PATH> are the values of the “Storage name:” and “Relative path:” fields of the project.

sudo -u git -- /opt/gitlab/embedded/bin/gitaly hooks set \
  --storage <STORAGE_NAME> \
  --repository <RELATIVE_PATH> \
  --config /var/opt/gitlab/gitaly/config.toml < custom_hooks.tar

<STORAGE_NAME> and <RELATIVE_PATH> are the values of the “Storage name:” and “Relative path:” fields of the project.

docker exec -i -u git code /opt/gitlab/embedded/bin/gitaly hooks set \
  --storage <STORAGE_NAME> \
  --repository <RELATIVE_PATH> \
  --config /var/opt/gitlab/gitaly/config.toml < custom_hooks.tar

Without Praefect, <STORAGE_NAME> and <RELATIVE_PATH> are the values of the “Storage name:” and “Relative path:” fields of the project:

d8 k -n code exec -i code-gitaly-0 -c gitaly -- gitaly hooks set \
  --storage <STORAGE_NAME> \
  --repository <RELATIVE_PATH> \
  --config /etc/gitaly/config.toml < custom_hooks.tar

With Praefect (global.praefect.enabled: true), run the command once for each storage from the Replicas list of the praefect metadata output. The pod name equals the storage name, for example code-gitaly-default-0; <REPLICA_PATH> is the Replica Path value:

d8 k -n code exec -i <STORAGE> -c gitaly -- gitaly hooks set \
  --storage <STORAGE> \
  --repository <REPLICA_PATH> \
  --config /etc/gitaly/config.toml < custom_hooks.tar

The module serves repositories through Praefect. Run the command once for each storage from the Replicas list of the praefect metadata output. The pod name equals the storage name, for example gitaly-default-0; <REPLICA_PATH> is the Replica Path value:

d8 k -n d8-code exec -i <STORAGE> -c gitaly -- gitaly hooks set \
  --storage <STORAGE> \
  --repository <REPLICA_PATH> \
  --config /etc/gitaly/config.toml < custom_hooks.tar

gitaly hooks set replaces the whole custom_hooks directory of the repository with the contents of the archive. To remove the project hooks, create an empty archive and load it with the same command in place of custom_hooks.tar:

tar -cf empty.tar -T /dev/null

Repository path on the storage

Repositories are kept in hashed storage: the directory of a repository is derived from an ID, so it does not change when the project is renamed or moved to another group. Without Praefect, the directory is derived from the project ID. With Praefect, Gitaly servers keep the repository under a replica path derived from the repository ID that Praefect assigns. Praefect is used in the Deckhouse Platform module and in the Helm Chart with global.praefect.enabled: true.

Storage name and relative path

The storage name and the relative path are shown in the Admin area:

  1. In the “Admin area”, go to “Instance overview” → “Projects”.
  2. Select the project.
  3. Copy the values of the “Storage name:” and “Relative path:” fields, for example default and @hashed/6b/86/6b86b273ff34fce19d6b804eff5a3f5747ada4eaa22f1d49c01e52ddb7875b4b.git.

With Praefect, “Storage name:” is the name of the virtual storage, and “Relative path:” is the path by which Praefect finds the repository. The directory on the Gitaly servers is in Path with Praefect.

The relative path is computed from the SHA-256 hash of the project ID: @hashed/<first two characters>/<next two characters>/<hash>.git. The project ID is shown on the project page, for example “Project ID: 42”. The wiki of the project is next to the repository, in <hash>.wiki.git. To compute the hash without the Admin area:

echo -n <PROJECT_ID> | sha256sum

The Rails console gives the same path by the full path of the project, and the project by the path:

Project.find_by_full_path('group/project').disk_path
# => "@hashed/6b/86/6b86b273ff34fce19d6b804eff5a3f5747ada4eaa22f1d49c01e52ddb7875b4b"

ProjectRepository.find_project('@hashed/6b/86/6b86b273ff34fce19d6b804eff5a3f5747ada4eaa22f1d49c01e52ddb7875b4b').full_path
# => "group/project"

The path in both commands has no .git suffix. The commands that open the Rails console for each installation type are in Service accounts.

Path without Praefect

The full path on disk is the storage directory followed by the relative path:

Installation typeStorage directory
Linux package/var/opt/gitlab/git-data/repositories
Omnibus Docker/var/opt/gitlab/git-data/repositories in the container, /srv/code/data/git-data/repositories on the host
Helm Chart/home/git/repositories in the Gitaly pod

For the example above on the Linux package, the repository is /var/opt/gitlab/git-data/repositories/@hashed/6b/86/6b86b273ff34fce19d6b804eff5a3f5747ada4eaa22f1d49c01e52ddb7875b4b.git.

Path with Praefect

Praefect stores the repository on the Gitaly servers under the replica path @cluster/repositories/<xx>/<yy>/<REPOSITORY_ID>, where <REPOSITORY_ID> is the ID assigned by Praefect; it differs from the project ID. Look the replica path up with praefect metadata, passing the values of the “Storage name:” and “Relative path:” fields:

The output names the replica path and the storages that hold a replica:

Repository ID: 54771
Virtual Storage: "default"
Relative Path: "@hashed/6b/86/6b86b273ff34fce19d6b804eff5a3f5747ada4eaa22f1d49c01e52ddb7875b4b.git"
Replica Path: "@cluster/repositories/6f/96/54771"
Primary: "gitaly-default-0"
Generation: 12
Replicas:
- Storage: "gitaly-default-0"
  Assigned: true
  Generation: 12, fully up to date
  Healthy: true
  Valid Primary: true
  Verified At: 2026-11-20 10:15:42 +0000 UTC
- Storage: "gitaly-default-1"
  ...

Each storage is a Gitaly pod of the same name, and its storage directory is /home/git/repositories. In the example, the repository is /home/git/repositories/@cluster/repositories/6f/96/54771 in the pods gitaly-default-0 and gitaly-default-1.

To go from a directory on a Gitaly server back to the project, pass the repository ID from the replica path to praefect metadata -repository-id <REPOSITORY_ID>, then look the “Relative Path” value without the .git suffix up with ProjectRepository.find_project in the Rails console.