创建git仓库及自动部署项目

Created: June 12, 2018, 11:11 p.m. Updated: June 12, 2018, 11:33 p.m.

git仓库安装

apt-get install git

adduser git

git:x:1001:1001:,,,:/home/git:/usr/bin/git-shell

新建仓库

git init --bare sample.git

chown -R git:git sample.git

clone到已存在目录

git clone --no-checkout /home/git/testproject.git tmp mv tmp/.git . rmdir tmp git reset --hard HEAD

git hook 自动部署

安装sudo

apt-get install sudo

修改/etc/sudoers git不需要密码之行

# Allow members of group sudo to execute any command
%sudo ALL=(ALL:ALL) ALL
git   ALL=(ALL) NOPASSWD: ALL

cd /home/git/testproject.git/hooks

cp post-update.sample post-update

修改脚本自动部署

#!/bin/sh

unset GIT_DIR
TARGET=/home/www/testproject
SVCNAME=testproject

cd $TARGET
sudo git add . -A 
sudo git stash
sudo git pull origin master
sudo chown -R www-data:www-data $TARGET

sudo supervisorctl restart $SVCNAME