Git Hook 同步服务器代码

参考并转载自:html

http://www.embbnux.com/2014/09/05/git_server_let_code_auto_deploy/git

http://www.chenyudong.com/archives/git-sync-manage-website.html#iweb

1. 建立远程仓库bash

$ 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 --bare
Initialized empty Git repository in /home/www.cnblogs.com/www.cnblogs.com.git/

2. 在git远端仓库的hooks目录下新建post-receive文件:post

#!/bin/sh
 
#author: embbnux
#Blog of Embbnux: http://www.embbnux.com
 
#判断是否是远端仓库
IS_BARE=$(git rev-parse --is-bare-repository)
if [ -z "$IS_BARE" ]; then
echo >&2 "fatal: post-receive: IS_NOT_BARE"
exit 1
fi
 
unset GIT_DIR
DeployPath="/var/web"
 
echo "==============================================="
cd $DeployPath
echo "deploying the test web"
 
git fetch --all
git reset --hard origin/master
 
time=`date`
echo "web server pull at webserver at time: $time."
echo "================================================"

  保存后赋予可执行权限:fetch

chmod +x hooks/post-receive
相关文章
相关标签/搜索