美文网首页
GIT服务端

GIT服务端

作者: 杏noclip | 来源:发表于2019-08-09 08:57 被阅读0次

登录安装git

$ ssh root@13.13.13.13
$ yum install git-core

创建用户

$ sudo adduser git
$ su git
$ cd ~
$ mkdir .ssh

保存用户公钥

$ cat /tmp/id_rsa.noclip.pub >> ~/.ssh/authorized_keys
$ chmod 700 ~/.ssh
$ chmod 600 ~/.ssh/authorized_keys

创建裸git库

$ cd /opt/git
$ mkdir project.git
$ cd project.git
$ git --bare init

$ chown -R git:git /opt/git/project.git

在 Noclip 的电脑上

$ cd myproject
$ git init
$ git add .
$ git commit -m 'initial commit'
$ git remote add origin git@13.13.13.13:/opt/git/project.git
$ git push origin master

其他人电脑

$ git clone git@13.13.13.13:/opt/git/project.git
$ cd project
$ vim README
$ git commit -am 'fix for the README file'
$ git push origin master

项目克隆到WEB目录

$ cd /data/wwwroot/
$ git clone /opt/git/project.git

创建git钩子,后置脚本

$ vim /opt/git/project.git/hooks/post-receive

#!/bin/sh

IS_BARE=$(git rev-parse --is-bare-repository)
if [ -z "$IS_BARE" ]; then
echo >&2 "fatal: post-receive: IS_NOT_BARE"
exit 1
fi

unset GIT_DIR
DeployPath="/data/wwwroot/www"

echo "==============================================="
cd $DeployPath
echo "deploying the test web"

git fetch --all
git reset --hard origin/master

time=`date`
echo "web server pull at webserver at time: $time."
echo "================================================"

$ sudo chmod +x /path/to/test.git/hooks/post-receive

相关文章

网友评论

      本文标题:GIT服务端

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