Automatic Server Deployment with Git/SSH

Uploading your files to servers is a pain. I was using git-ftp previously. But i wanted to use a pure git protocol coupled with ssh.

Copy your existing working directory to your server in lets say /var/www to be served as web; make sure it contains a .git folder.

on your local machine:
git remote add myserver nayar@example.com:/var/www/.git

on your server:
cd /var/www
git config receive.denyCurrentBranch ignore
mv ./.git/hooks/post-update.sample ./.git/hooks/post-update
chmod a+x post-update

modify the contents of ./git/hooks/post-update as follows

#!/bin/sh
GIT_WORK_TREE=/var/www/ git reset –hard

The setting up is over. Lets test if it’s working:-

on your local machine:
Make some changes to your local files
git commit -a -m 'changing file x'
git push origin master

The files on your server should have been updated accordingly 😉

Leave a Reply

Your email address will not be published. Required fields are marked *