Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am using Gitlab on one server and would like to push my git repository on commit of the master branch to another webserver. So when I push a new version of the website the production server gets updated. I know this should be possible with hooks inside gitlab but I am unable to find how exactly. Tried the following guide but it is not written for use with gitlab so Im missing parts.

What do I need to do on the production webserver and what do I set the hook URL to then?

share|improve this question
you can use the regular git hooks, if you have root access to the git server, see post-commit hook here: – Doka Nov 9 '14 at 13:27
You can try Custom Git hooks. – monsta Dec 24 '14 at 10:58

gitlab already uses the post-receive hook internally. you could fiddle around with that script and call your hook as well, but from the docs it looks like the "official" way would be to use "web-hooks", i.e. let gitlab call your webserver on post-receive and your webserver then pulls the repository. I haven't tried this myself, but since no one answered so far I thought I'd point you in that direction:

to enable web-hooks go into your project's main page and select hooks from the top right, below the main menu. ( ). there is an example&docs linked from that page ( ).


I tried it this morning. Here is a php script example. It assumes the you have already cloned the repo and the webserver has all the necessary permissions/ssh keys set up.


$json= file_get_contents('php://input');
 $cmd="git --work-tree=$mirrordir --git-dir=$gitdir pull";
share|improve this answer
yes I know where to find the hooks page. I just don't know how the file should look like gitlab should post to. – Tristan van Bokkem Jan 6 '13 at 21:51
see edited answer, I added an example script. may not be perfect but at least a quick test seems to work – Gryphius Jan 7 '13 at 8:04

Gitlab doesn't have a post-receive hook since the developers replaced gitolite with gitlab-shell.

Therefore you can:

sudo -u git bash
touch /home/git/repositories/<repository name>.git/hooks/post-receive
vim /home/git/repositories/<repository name>.git/hooks/post-receive

Make sure the git user has all the permissions needed to run the commands in this file

share|improve this answer
hook folder already exist: hooks -> /opt/gitlab/embedded/service/gitlab-shell/hooks/ – MᴀʀɪᴜsᴢS Dec 5 '14 at 18:21

Custom hooks were recently added (since as Gryphius said the regular hooks are used internally):

You just create a custom_hooks directory in you bare Git repo, and put the hooks in it, and then GitLab makes sure they get run.

share|improve this answer

Sorry, I can't answer in the comments. I tried the solution from Gryphius. I modified it a little bit and it works if I call my PHP script in the browser (via GET). If I test the webhook of Gitlab it doesn't work, because it sends it as POST. Why isn't the script executed as POST?

$dir = "/srv/www/vhosts/";

$output = shell_exec("cd ".$dir);
echo $output;
$cmd = "git pull origin master";
$output = shell_exec($cmd);
echo $output;
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.