GIT Server Buildup and Hooks Setting Up on Raspberry Pi

1, Set up git envioronment

sudo apt-get install git
sudo adduser git

2, Generate public and private key

ssh-keygen -t rsa -C “user@lazying.art” 

Client:

/home/pi/.ssh/id_rsa

Server: add public key of each client to the file below

/home/git/.ssh/authorized_keys 

3, Initialize server end envioronment

mkdir Git
cd Git
sudo git init --bare sample.git
sudo chown -R git:git sample.git
vim /etc/passwd
git:x:1001:1001:,,,:/home/git:/bin/bash
git:x:1001:1001:,,,:/home/git:/usr/bin/git-shell

4, Upload code to your github server

git config --global user.email "you@example.com"
git config --global user.name "Your Name"
git add .
git commit -m "init commit"
git push -u origin master

5, Set-up Hooks

vim sapmle.git/hooks/post-receive

Add code below to post-receive

#!/bin/bash
TARGET="/home/webuser/deploy-folder"
GIT_DIR="/home/webuser/www.git"
BRANCH="master"

while read oldrev newrev ref
do
	# only checking out the master (or whatever branch you would like to deploy)
	if [ "$ref" = "refs/heads/$BRANCH" ];
	then
		echo "Ref $ref received. Deploying ${BRANCH} branch to production..."
		git --work-tree=$TARGET --git-dir=$GIT_DIR checkout -f $BRANCH
	else
		echo "Ref $ref received. Doing nothing: only the ${BRANCH} branch may be deployed on this server."
	fi
done
chown git:git hooks/post-receive
chmod +x hooks/post-receive
Counting objects: 2, done.
 Delta compression using up to 8 threads.
 Compressing objects: 100% (2/2), done.
 Writing objects: 100% (2/2), 237 bytes | 23.00 KiB/s, done.
 Total 2 (delta 0), reused 0 (delta 0)
 remote: Ref refs/heads/master received. Deploying master branch to production…
 remote: error: unable to create file main.py (Permission denied)
 remote: error: unable to create file test.py (Permission denied)
 remote: Already on 'master'
 To 192.168.1.108:/home/pi/Git/printer.git
    2e6a796..6085cd0  master -> master

Causing of the hooks script cannot access deployment files, you should change the owner of deployment directory to git

chown git:git /path/to/deployment/directory/
Counting objects: 2, done.
 Delta compression using up to 8 threads.
 Compressing objects: 100% (2/2), done.
 Writing objects: 100% (2/2), 239 bytes | 21.00 KiB/s, done.
 Total 2 (delta 0), reused 0 (delta 0)
 remote: Ref refs/heads/master received. Deploying master branch to production…
 remote: Already on 'master'
 To 192.168.1.108:/home/pi/Git/printer.git
    6085cd0..b83c0d5  master -> master

________

1.在文件所在位置打开终端,输入如下命令,进行git全局设置:

git config –global user.name “用户名”
git config –global user.email “用户邮箱”

  1. 安装如下命令创建新的仓库,网址为自己新建项目的网址,cd转到自己要上传的项目文件夹:

git clone https://git.aiiage.com:9999/song.yl/ReID.git
cd ReID
touch README.md
git add README.md
git commit -m “add README”
git push -u origin master

  1. 对已经存在的文件夹进行操作, 可以不用cd命令转到文件夹,直接到文件夹下打开终端执行如下命令,其中git commit命令后引号里面的内容可以自己命名:

cd existing_folder
git init
git remote add origin https://git.aiiage.com:9999/song.yl/ReID.git
git add .
git commit -m “Initial commit”
git push -u origin master

  1. 对存在的git仓库进行操作。依然可以直接在所在文件夹直接打开终端执行命令:

cd existing_foloder
git remote rename origin old-origin
git remote add origin https://git.aiiage.com:9999/song.yl/ReID.git
git push -u origin —all

git push -u origin –tags

作者:yllifesong
来源:CSDN
原文:https://blog.csdn.net/yllifesong/article/details/81041156
版权声明:本文为博主原创文章,转载请附上博文链接!

Leave a Reply

en_USEnglish