views:

88

answers:

2

I work on a git repository where we build an php community but i need to show it somewhere so I am looking for a way to automatic upload my files to a remote http server when i push to the repository.

Thanks /Victor

+1  A: 

Like Subversion Git offers a hook mechanism, too. Check out the githooks man page. Basically you just need to write a checkout and deploy script for your PHP application as a post-commit hook.

For github you should have a look at their webhooks mechanism.

Daff
Please, explain more.Thanks for quick answer.
Victor
Well if you use your own git repository you can write shell scripts that will be executed after a certain event(e.g. post-checkout, pre-commit, post-commit) occurrs. That shell script then just needs to checkout the repositoryto the server you want to run it. Github (which you tagged this question with) uses a similar mechanism called webhooksthat call a certain URL instead of a shell script.
Daff
Oh, now I understand, thank you very much for a well explained answer and the fast response!
Victor
A: 

If there is no separate git repo on the second server, I would export files from archive:

git checkout-index -a -f --prefix=/target/path/

And then used sftp to synchronize with remote server:

#!/bin/bash
HOST="ftp.example.com"
USER="user"
PASS="pass"
LCD="/var/www/yourdir"
RCD="/www/"
lftp -c "
#debug;
open ftp://$USER:$PASS@$HOST;
lcd $LCD;
cd $RCD;
mirror --only-newer \
       --reverse \
       --verbose \
       --exclude-glob somepattern ";

You may automate this process as a build script (e.g. Phing), our bind as a post commit git hook, like it has been mentioned before.

takeshin