Skip to content

Instantly share code, notes, and snippets.

@mosufy
Last active August 29, 2015 14:13
Show Gist options
  • Save mosufy/ad496bffd33ce60f7558 to your computer and use it in GitHub Desktop.
Save mosufy/ad496bffd33ce60f7558 to your computer and use it in GitHub Desktop.
Git Push to deploy setup

Setup GIT push-to-deploy

Push to remote repo will automagically update the files.

  1. Set-up bare git on remote

     $ cd /var/www/{appfolder}
     $ sudo mkdir .git
     $ cd .git
     $ sudo git init --bare
    

This will initialize a bare git repository on remote machine 2. Create post-receive hook

    $ sudo nano hooks/post-receive
    ================================================
    #!/bin/sh
    GIT_WORK_TREE=/var/www/{appfolder} git checkout -f master
    -- OR --
    GIT_WORK_TREE=/var/www/{appfolder} git checkout -f develop
    -- OR --
    GIT_WORK_TREE=/var/www/{appfolder} git checkout -f features/{feature_name}

The last column is to check-out the relevant branches. 3. Make post-receive hooks executable

    $ sudo chmod +x hooks/post-receive
  1. Make .git folder writeable to user

     $ sudo chown -R ubuntu .
    
  2. Make www folder writable to user

     $ cd /var/www
     $ sudo chown -R ubuntu:www-data {appfolder}/.
    
  3. Add remote repo to your local git workstation and push to deploy!

Please ensure that your files are writable by www-data (AWS Ubuntu) or ec2-user (AWS CentOS)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment