How to perform automatic pull with Git?

9

Imagine that I have an environment for testing a web application, where there is a cloned GitHub repository that goes right inside the server, and any modification in it already results in a real-time modification when the user accesses the same via browser.

My question is, is there any way to add a listener to this local repository so that whenever there is a change in the official repository (GitHub) it already automatically downloads the changes? Illustration to facilitate understanding:

I've been searching and found nothing about it, but I know that to update my local repository, the command would be:

$ git pull origin master

Is there any solution from Git itself or Gulp for this kind of listener ?

    
asked by anonymous 21.12.2014 / 17:50

1 answer

8

You can use a web hook provided by Github API . He is your listener .

Git Documentation for hook configuration.

To get what you want very automatically you will need to write a script . An example .

A simple example:

Create a script that does pull . Example:

#!/bin/bash
echo "Content-type: text/plain"
echo ""
cd ~/project
git pull

Register the URL of this script in Github in the Webhooks & Services option (in Settings ) by creating a new webhook and accepting everything as the default. It will be called when a change occurs in the repository.

In the background the only action really needed in script is git pull . It depends on how you want to deploy and how your Git is configured.

Obviously script must be accessible via HTTP and proper execution permission is required.

    
21.12.2014 / 18:17