title: Automating php deployment on multiple servers with git hooks
body: <p>Recently we have started exploring GIT with the target of enabling our developers to work from any place and secondly to automate the overall deployment process. </p>
  
  <p>We have a central test server where we host all apps/sites for testing and/or demo purpose and once  the development and testing is finalized we move the application to their respective live servers.</p>
  
  <p>Whatever i have set up with GIT, is as follows<br>
  1. Create a bare repo on test server<br>
  2. Get a local clone for each involved developer, Developers will push to remote(test server) dev branch<br>
  3. Someone will merger all changes from dev branch to master branch and push it to remote<br>
  4. The test server (bare repo) has a post-receive hook, which checks out the master branch to public_html folder (using GIT_WORKING_DIR and checkout -f).   </p>
  
  <p>As of now, everything works good and i am able to see merge on master branch on hosted pages (on test server, of course). Now my questions are ...<br>
  1. Am I doing this right?<br>
  2. I guess the post-receive hook I have set, executes on push to dev branch as well. How to avoid this?<br>
  3. How I can ship these contents to my live server? As I have some projects with large code base, checking out everything on test server and then ship it to live doesn't looks good enough.  </p>
  
  <p>I've heard of CI servers, but as much as I know they check out locally and upload <strong>everything</strong> to live using 'rsync' (don't know if it just syncs changes or uploads everything) or such tools. I just want to avoid that <strong>everything</strong> part and keep an option open to rollback, if anything goes wrong. I am good with setting up git on live servers. </p>