簡單記錄一下過程:
建立伺服器上所需要的遠端倉庫
1 2 3 4
| cd /git/ mkdir category && cd category mkdir apps.git && cd apps.git git init --bare --shared
|
建立勾子 (當接收到 PUSH 後)
1
| cd hooks && touch post-receive
|
關於 post-receive 的內容如下 (作出了相應的修改)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| # Source : http://icyleaf.com/2010/09/apps-auto-deploy-with-git/ # Modifier: Zeuxis
IS_BARE=$(git rev-parse --is-bare-repository) if [ -z "$IS_BARE" ]; then echo >&2 "fatal: post-receive: IS_NOT_BARE" exit 1 fi
SUBJECT=$(git log -1 --pretty=format:"%s")
DEPLOY_DIR=/path/to/example.com if [ ! -d $DEPLOY_DIR ] ; then echo >&2 "fatal: post-receive: DEPLOY_DIR_NOT_EXIST: \"$DEPLOY_DIR\"" exit 1 fi
cd $DEPLOY_DIR || exit unset GIT_DIR git pull
|
將 post-receive 的權限改為可執行
切換到自己的根目錄,並 Clone 一份
1 2 3
| cd /path/to git clone /path/from/git/category/app.git /path/to/example.com chown -Rf git:USERNAME example.com
|
在自己的機子上建立本地倉,並將資料都加進去,之後就可以通過PUSH,再由勾子更新網站的目錄
1 2 3 4 5 6
| cd /local/category/app git init git remote add origin [email protected]:category/app.git git add . git commit -am 'init repo' git push origin master
|