Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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

2 Answers 2

up vote 2 down vote accepted

Yes.

Create a shell script with something like:

#!/bin/sh
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 getsite.sh

Make sure your file is executable:

chmod +x /scripts/getsite.sh

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

/scripts/getsite.sh

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/getsite.sh

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 http://debuggable.com/posts/git-tip-auto-update-working-tree-via-post-receive-hook:49551efe-6414-4e86-aec6-544f4834cda3

and

http://www.turnkeylinux.org/blog/website-synchronization

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

share|improve this answer

Your Answer

 
discard

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.