服务端
创建一个git用户
adduser git
禁用shell登陆
git:x:1000:1000::/home/git:/bin/git-shell
git用户加入ssh共钥,使用vim将公钥添加到authorized_keys文件中,一行一个
cd /home/git
mkdir .ssh
touch authorized_keys
opt目录下创建一个文件夹code
mkdir /opt/code
进入文件夹后创建一个git空仓
cd code
git init --bare test.git
git目录加权限,否则提交的时候会出现错误
chown -R git:git test.git
自动部署
cd hooks
vim post-receive
内容为重写指定工作区文件,代码如下
#!/bin/bash
git --work-tree=/www/wwwroot/test checkout -f
实际情况应将‘/www/wwwroot/test’替换为目标项目位置,此目录git用户需有权限
chown -R git:root /www/wwwroot/test
服务端环境目录拉取
git clone /opt/code/test.git
用户端
git clone git@IP:/opt/code/test.git
最后随意提交一次git查看效果
参考原帖子
http://www.imooc.com/article/17874?block_id=tuijian_wz
http://www.imooc.com/article/18201
https://www.lagou.com/lgeduarticle/63914.html