git hook裸仓库自动部署
1.在服务器上创建裸仓库 git init --bare 2.git裸仓库钩子在hooks/中 进入hooks中 $ cd git/hooks $ touch post-receive && vim post-receive 在 post-receive文件中添加一下内容: #!/bin/sh DEPLOY_PATH=/home/wwwroot/default/myproject/ #这个路径是服务器上项目的目录位置 unset GIT_DIR #这条命令很重要 cd $DEPLOY_PATH git reset --hard git pull chown root:root -R $DEPLOY_PATH 保存文件并修改权限: chmod +x post-receive 3.服务器上的项目目录克隆git上的项目地址(用ssh地址,需要把服务器的上公钥添加到git上) 4.在自己的电脑上,生成公钥,在服务器的~/.ssh/authorized_keys 的文件中添加上你本地电脑的公钥 5.在本地的仓库中使用命令: git remote add server ssh://root@<服务器ip地址>/<服务器git目录地址> 6.在本地修改好代码后,提交到远端,git push到master 7.执行git push server 远端自动拉取代码 来源: 51CTO 作者: