一、git用戶執行 git push
操做html
二、遠程倉庫發現有用戶執行了push操做,就會執行一個腳本 post-receive
(鉤子)git
三、在 post-receive
腳本中,將git倉庫的代碼拷貝到web站點目錄下web
sudo yum install git cd ~ git init git init --bare www.xx.com
二者區別:vim
一、普通git倉庫的目錄結構就和你的代碼目錄結構一致,只多了.git目錄,.git目錄中包含了git的一些配置等數據服務器
二、裸倉庫只保存了一些配置信息等,肉眼是找不到咱們所上傳的代碼的(建議
)ssh
git clone ~/www.xx.com
這樣網站目錄就有一份倉庫的完整代碼post
接下來寫hook文件網站
cd ~/www.xx.com/hooks vim post-receive
在post-receive鉤子文件裏寫如下內容code
#!/bin/sh unset GIT_DIR cd /var/www/html/website git pull
編輯後保存退出。以上命令表示cd到網站目錄,並git pull更新。隨後還要把post-receive改爲可執行:htm
chmod 775 post-receive
git clone ssh://git@127.0.0.1:22/~/www.xx.com git add . git commit -m='' git push