git的hooks自动部署设置学习分享

服务器环境:阿里云服务器centos,lnmp


1、首先参照菜鸟教程中git教程安装git,网址:http://www.runoob.com/git/git-remote-repo.html

2、搭建git远程仓库:

1、安装Git

$ yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel perl-devel
$ yum install git

接下来我们 创建一个git用户组和用户,用来运行git服务:

$ groupadd git
$ adduser git -g git

2、初始化Git仓库

首先我们选定一个目录作为Git仓库,假定是/home/gitrepo/runoob.git,在/home/gitrepo目录下输入命令:

$ cd /home
$ mkdir gitrepo
$ chown git:git gitrepo/
$ cd gitrepo

$ git init --bare runoob.git     //注意要加  --bare
Initialized empty Git repository in /home/gitrepo/runoob.git/

3、克隆仓库

$ git clone git@192.168.45.4:/home/gitrepo/runoob.git
Cloning into 'runoob'...
warning: You appear to have cloned an empty repository.
Checking connectivity... done.


设置好git远程仓库之后,设置该仓库的所属用户和组为git用户,chown -R git:git /home/runoob,git

在远程仓库runoob.git/hooks/新建post-receive,加入如下脚本:

#!/bin/sh
git --work-tree=/home/wwwroot/basic --git-dir=/home/warehouse/myyii.git checkout -f

前边为web目录路径,后边为仓库路径,改为自己的路径。 并给脚本添加可执行权限:chmod +x /home/runoob.git/hooks/post-receive


然后要保证git用户对web目录下的文件有写权限,所以要把git用户加入到web用户组中。这里我使用的lnmp一键安装包搭建的环境,web目录用户是www用户。

执行命令:usermod -a -G www git



这样在执行git的push操作时会自动调用hooks中的文件。将代码自动发布到web目录。


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值