码迷,mamicode.com
首页 > 其他好文 > 详细

Git Hook 同步服务器代码

时间:2015-10-07 21:31:49      阅读:294      评论:0      收藏:0      [点我收藏+]

标签:

参考并转载自:

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. 创建远程仓库

$ 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文件:

#!/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 "================================================"

  保存后赋予可执行权限:

chmod +x hooks/post-receive

  

Git Hook 同步服务器代码

标签:

原文地址:http://www.cnblogs.com/chemandy/p/4859533.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!