Git hooks I use on my gitolite server
Switch branches/tags
Nothing to show
Clone or download
Latest commit 0e430aa Feb 25, 2013
Type Name Latest commit message Commit time
Failed to load latest commit information. Typo Feb 24, 2013
jgit Initial commit Oct 27, 2012

Git Hooks

This is a pair of git hooks that I use on my gitolite server that facilitate a few interesting things:

Repository-specific pre- and post-receive hooks

You can embed little scripts inside the config, specific to each repo. Each script will be invoked once for every branch with an optional regex filter. For example:

repo testing
  config hooks.pre         = ""
  config hooks.pre.filter  = "master$"
  config        = ""
  config = "master$"

Simple mirroring

Gitolite has a sophisticated mirroring system built in for mirroring between muliple gitolite instances. This doesn't really help when you want to push to Github or S3. To set up a mirror, create a config key for that repo named mirror.<name> with the value set to the remote URL.

repo testing
  config mirrors.github = ""
  config mirrors.s3     = "amazon-s3://.jgit@bugsplat-git-repos/testing.git"
  config mirrors.other  = ""

To push to S3 you'll need to create a bucket on S3 and create a file in the gitolite user's home directory that contains your access key and secret key in this format:


Your mirror URL will then be in the format amazon-s3://<filename>@<s3-bucket-name>/<repo_name>.git. In the example above, the key file is at $GITOLITE_HOME/.jgit.

Maintain a local clone

Sometimes it's really useful to have a local clone of a particular repository. These hooks let you do that by setting a config entry named hooks.clone.path to the path where the clone should exist. Note that any changes made to this clone will be erased the next time you push.

repo testing
  config hooks.clone.path = "/var/repos/testing"


Copy pre-receive and post-receive to $GITOLITE_HOME/.gitolite/hooks/common and make sure they're executable. Copy jgit to $GITOLITE_HOME/bin/jgit. Customize the constant REPO_BASE at the top of post-receive to point the correct location for your system.