By alexmoreno, 7 December, 2012

There is a simple way of upgrading or executing a command immediatly after a push has been done.

We just need to go to the server repository (the one which is going to receive the push), and enter in hooks (.git/hooks or hooks if it's a bare repository).

Then, we rename the post-receive.sample to post-receive, without extension, and add this content:

echo "********************"

echo "Post receive hook: Updating User Staging"

echo "********************"

cd ../live

GIT_DIR='.git'

git pull origin master

echo "********************"

echo "Post receive hook: Updating User Staging"

echo "********************"

You'll just have to change the ../live path with the place where your live git code lives, and the next time you make a commit, the live directory will be automatically updated with a git pull.

It is not the perfect way of going live, is my case this is a staging server, so it's fine. If you need to go to "real" live, Capistrano is what you are looking for. We'll speak about it next weeks.

categorias