美文网首页
git安装及自动化

git安装及自动化

作者: AnneSan | 来源:发表于2018-12-19 15:38 被阅读0次

参考文档:https://tzhennan.iteye.com/blog/2419387

服务器上的操作;

Git 安装

# yum install httpd(apache2)

# yum install git 

创建git用户名:

#useradd git

# passwd git(给git设置密码)

切换到git用户:

#su git

初始化一个git项目

$ git init --bare ~/repo/website.git     (表示在git用户的home/repo文件夹中,建立website.git仓库)

到网站(/var/www/html),克隆一份website代码:

$ cd /var/www/html

$ git clone ~repo/website.git(/var/www/html/website是你网站的根目录)

改写hook文件:

$ cd ~/repo/website.git/hooks

$ vim post-receive

在post-receive钩子文件里写以下内容:

#!/bin/sh

unset GIT_DIR

cd /var/www/html/website

Git pull

退出保存后,改变post-receive的权限:

$ chmod 775 post-receive

在网站/var/www/html/website下测试:

git pull

客户端的操作:

安装git:(省略)

远程连接git:

git clone git@123.232.23.12:/home/reop/website.git

测试git:

增加一个文件,如.txt

Git add .

Git commit -m ‘first’

Git push

成功后,查看服务器网站目录下website  有没有自动同步

如果没有的话检查hooks/post-receive文件是否有问题

Cd /home/repo/website/hooks

Sh post-receive  (如果命令报错,请检查代码规范)

相关文章

网友评论

      本文标题:git安装及自动化

      本文链接:https://www.haomeiwen.com/subject/fitphqtx.html