一、准備環境
CentOS 7.2 服務器中下載git 版本為2.13.1
安裝依賴
yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel asciidoc
yum install gcc perl-ExtUtils-MakeMaker
卸載git-1.8.3.1版本
yum remove git
下載git-2.13.1.tar.gz
wget https://www.kernel.org/pub/software/scm/git/git-2.13.1.tar.gz
tar zxvf git-2.13.1.tar.gz
cd git-2.13.1
make prefix=/usr/local/git all
make prefix=/usr/local/git install
echo "export PATH=$PATH:/usr/local/git/bin" >> /etc/profile
source /etc/profile
二、創建git用戶
useradd git #給Linux系統添加git用戶
passwd git #設置git用戶密碼
創建服務器端倉庫
mkdir /home/git/tp5.git
cd /home/git/tp5.git
git init --bare
進入hooks目錄
cd hooks
·
創建post-receive文件
touch post-receive
向post-receive中寫入代碼
vim post-receive
#demo-brancd 表示demo分支,不寫默認master分支
#!/bin/sh
DIR=/home/wwwroot/default #此次為nginx服務器站點代碼
git --work-tree=${DIR} clean -fd demo-brancd
git --work-tree=${DIR} checkout --force demo-brancd
chown git:git post-recevice #授權給git用戶
chmod +x post-recevice 授權post-recevice可執行·
錯誤一:
(如果客戶端執行git push 報錯:Permission deied)給/home/wwwroot/default 目錄授予git用戶寫入的權限
錯誤二:
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
客戶端創建ssh的id_rsa、id_rsa.pub公鑰添加到自己的服務器
ssh-keygen -t rsa -C "xxxx@qq.com"