环境:centos7
目标:
本地代码提交到远程仓库,触发远程仓库hook,hook脚本pull代码到项目目录
实现:
略过手动创建服务端仓库,ssh公私钥
服务器仓库地址:
/git/hello-world.git
配置 git hook
$ cd /git/hello-world.git/hooks
$ vi post-receive
写入以下内容
#!/bin/sh
unset GIT_DIR
NowPath=`pwd`
#项目目录
DeployPath="/data/code/hooks_test"
cd $DeployPath
git reset --hard && git clean -f && git pull 2>&1
cd $NowPath
exit 0
给权限
$ chmod +x post-receive
服务器项目目录下拉代码
$ sudo -u git git clone /git/hello-word.git
最后在本机客户端提交测试,查看服务器目录代码是否更改