Ankit Ahuja

Deploying on Dreamhost Using Git

I’ve done this for multiple sites (including a Wordpress blog) and thankfully I wrote down the instructions when I did it the first time. I find this way to deploy really useful. It gives you version control, and an easy and quick way to deploy small, incremental changes. Deploying is as simple as executing git push live from the command line.

Here are the step-by-step instructions to follow assuming the site name to be rainbow:

  • Add or update the robots.txt in the containing folder of rainbow
    User-agent: * Disallow: /relative-path-to-rainbow

  • To avoid entering your password every time, copy your SSH public key to the server using ssh-copy-id. On Mac, you can install ssh-copy-id using homebrew

    brew install ssh-copy-id

  • Make sure you have local SSH keys setup. Then, do

    ssh-copy-id -i user@domain.com

  • SSH into the server

    ssh user@domain.com

  • Navigate to where you want to deploy your site on the server. Then, do

1
2
3
4
5
6
mkdir rainbow
cd rainbow
git init
git config receive.denyCurrentBranch ignore   
curl https://raw.github.com/gist/2715777/c44c8f05711182c58aed2dace960614729aa916c/git_dreamhost_deploy.sh > .git/hooks/post-upda
chmod +x .git/hooks/post-update   
  • In your local repository, add the remote (say live) pointing to the repository on the server:

    git remote add live ssh://user@domain.com/absolute-path-to-rainbow

  • In your local copy, push to the remote repository

    git push live master

  • On the remote repository, you may need to do git checkout master the first time to see the changes.

  • That’s it! Whenever you need to deploy, just do

    git push live

Reference

http://stackoverflow.com/questions/279169/deploy-php-using-git