lafif-a
11/18/2014 - 6:36 AM

[Git] Automatic Deployment with git hooks

[Git] Automatic Deployment with git hooks

/**
 * Create directory and init as --bare repo
 */

mkdir repo && cd repo
mkdir site.git && cd site.git
git init --bare


/**
 * Goto /hooks/ and create post-receive file with the following script
 * @work-tree : your public_html location
 * @git-dir : your git directory
 */

#!/bin/sh
git --work-tree=/var/www/domain.com --git-dir=/var/repo/site.git checkout -f

/**
 * Change file permision so that can be excuted
 */

chmod +x post-receive

/**
 * Add remote on local git ponted to your server git
 */

git remote add production ssh://user@mydomain.com/var/repo/site.git

/**
 * For cpanel server, please add this line on .git/config
 * Example: 
 *
 * url = user@mydomain.com/var/repo/site.git
 * fetch = +refs/heads/*:refs/remotes/upstream/*
 * receivepack = /usr/local/cpanel/3rdparty/bin/git-receive-pack
 */
 
 receivepack = /usr/local/cpanel/3rdparty/bin/git-receive-pack