Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

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 have a private GitHub repo that I'd like to setup my testing server (LAMP) to automatically pull/fetch the files in the master branch and put them in my web root (/var/www).

Wouldn't it be possible to create a shell script that would cd to /var/www and then run git pull origin master? Could I do this using a CRON job?

share|improve this question
up vote 3 down vote accepted


Create a shell script with something like:

cd /var/www
git pull origin master

You can store the file wherever you like. Let's assume in /scripts/ Let's assume it's called

Make sure your file is executable:

chmod +x /scripts/

Run the command to make sure it works. I'll assume you've already run git init, and setup the repo.


Assuming it works OK, you can create a crontab entry to run it as often as you see fit:

crontab -e

You'll need an entry something along the lines of:

59 23 * * * /scripts/

This would run the script at 23:59 every day.

Read up on the man page for crontab if you need help with it.

share|improve this answer
Thanks! That worked. – Trent Scott May 19 '11 at 17:53

The answer is yes--but you have a few different options to consider. The basic idea is chaining events together, whether you use git-hooks or rsync and cron or even Dropbox.

For more ideas, take a look at


Do a search for git-hooks and push/pull and you should find plenty of info.

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.