Reference and reprint from:
http://www.embbnux.com/2014/09/05/git_server_let_code_auto_deploy/
Http://www.chenyudong.com/archives/git-sync-manage-website.html#i
1. Create a remote repository
$ mkdir/home/www.cnblogs.com/www.cnblogs.com.git #将来网站git的记录存放位置 $ chown-r git:git www.cnblogs.com.git #改权限 $ cd www.cnblogs.com.git$ git init--bareinitialized empty git repository in/home/www.cnblogs.com/www.cnblogs.com.git/
2. Create a new post-receive file in the hooks directory of the Git remote repository:
#!/bin/sh #author: Embbnux#blog of embbnux:http://www.embbnux.com #判断是不是远端仓库IS_BARE =$ (git rev-parse-- is-bare-repository) If [-Z] $IS _bare "]; Thenecho >&2 "Fatal:post-receive:is_not_bare" Exit 1fi unset git_dirdeploypath= "/var/web" echo "=============== ================================ "CD $DeployPathecho" Deploying the Test Web "git fetch--allgit reset--hard origin/maste R time= ' Date ' echo Web server webserver at time: $time. " echo "================================================"
Grant executable permissions after saving:
chmod +x hooks/post-receive
Git Hook Sync Server code