標籤:
參考並轉載自:
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 --bareInitialized 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" ]; 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/master time=`date`echo "web server pull at webserver at time: $time."echo "================================================"
儲存後賦予可執行許可權:
chmod +x hooks/post-receive
Git Hook 同步伺服器代碼