GIT服务器端部署及自动拉取

GIT服务器端部署及自动拉取

文件名称

1
post-receive

文件路径

裸仓库,对应服务器端.git目录

文件位置参考:

1
~/org.git/hooks/post-receive

脚本内容

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#!/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/data/com.termux/files/home/org"

echo "==============================================="
cd $DeployPath  #进入web项目目录
# echo "deploying the web project"
echo "auto pull"

#git stash
#git pull origin master #不建议使用git pull,后面会有解释

git fetch --all  #这里使用git fetch进行拉取,不建议用git pull
git reset --hard origin/master

#gitbook build  #这里的gitbook是一个电子文档管理软件,用于生成好固定格式的电子文档,一般用户到,若需要则需另行安装,由于gitbook是node.js写的,而npm是node.js的包管理器,所以要先安装npm再安装gitbook。gitbook build表示文档生成在当前目录的默认文件夹_book里面。
#sleep 15 #gitbook执行需要8秒钟时间,等待15秒是为了确保能得到返回结果

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

文件需要可执行权限

1
chmod +x post-receive
Licensed under CC BY-NC-SA 4.0
最后更新于 Sep 09, 2025 10:40 +0800
comments powered by Disqus
使用 Hugo 构建
主题 StackJimmy 设计