Automatic Pull on Server documentation: “Every GitHub repository has the option to communicate with a web server whenever the repository is pushed to. These “webhooks” can be used to update an external issue tracker, trigger CI builds, update a backup mirror, or even deploy to your production server.

Each hook can be configured for a specific service and one or more events, regardless of the API used to do so. Repository admins can configure hooks programmatically via the API.”

In this recipe, we are going to show howto do a simple automatic pull to any repository.  Before you take this steps, make sure you have the right permissions to the repository and that the appropiate group and user have the permissions to do a pull. To know how to configure a repository  for several users, follow this recipe on How to setup a shared GIT repo.

Subscribe to our blog to learn about staff augmentation, software development,  and more.

1. Go to the github respository Settings

Under settings, go to Webhooks and Services and Add webhook.

Put the url of the file you are going to use on the server to do the automatic pull. E.g

Make sure is active and the “just the push event” is selected.

If you want add a secret, but not necessary.

2. Server work

Go to the server and create a file called pull.php on the base of the repository.  E.g. sudo touch /var/www/drupalsites/xx/pull.php

3. Insert the following code to the pull.php file you just created


// Use in the “Post-Receive URLs” section of your GitHub repo.

if ( $_POST['payload'] ) {
shell_exec( ‘cd /var/www/drupalsites/git-repo/ && git reset –hard HEAD && git pull’ );


4. You are done!

Enjoy automatic pulls.