参考链接 :https://ourai.ws/posts/deployment-with-git-hooks/
1,处理ssh密钥登陆见上篇
2.服务器需要两个仓库,一个是裸仓库,不能直接看到上传的文件。 一个是工作仓库,需要用钩子代码,把裸仓库里的pull过来。
3. 在本地上传常用:
$ git init $ git add yourfile $ git remote add origin git@yourserverip:/xxx/xxx/xxx $ git commit -m '' $ git push origin master
4.在工作仓库需要先运行:
git init git remote add origin ~/repos/BRIDGE_REPO.git git fetch git checkout master
5.钩子: post-receive
文件名:
代码:
6.注意权限问题。#!/bin/sh unset GIT_DIR NowPath=`pwd` DeployPath="../../www" cd $DeployPath git pull origin master cd $NowPath exit 0