本地创建git服务器实践

本地创建git服务器实践

 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
30
31
32
# 1. 创建临时目录(实际创建),并添加 .git 后缀作为裸仓库路径
#    注意:mktemp -d 会立即生成目录,realpath 用于规范化路径
git_bare_repo="$(realpath $(mktemp -d -p ./ XXXXXXXX.git))"; echo ${git_bare_repo}
# 2. 在该路径下初始化裸仓库(服务仓库)
git init --bare "${git_bare_repo}"

# 3. 克隆裸仓库,得到工作副本(默认目录名为裸仓库名去掉 .git)
git clone "${git_bare_repo}"

# 4. 查看当前目录内容(示例输出如下)
#    tmp.Vu2uRXzxuX  tmp.Vu2uRXzxuX.git
ls

# 5. 进入工作副本目录
cd "$(basename "${git_bare_repo}" .git)"

# 6. 添加子模块(需代理访问 GitHub)
# git submodule add https://github.com/CaiJimmy/hugo-theme-stack/ themes/hugo-theme-stack
git -c http.proxy=127.0.0.1:10808 submodule add \
    https://github.com/CaiJimmy/hugo-theme-stack/ themes/hugo-theme-stack

# 7. 提交并推送变更到裸仓库
git add .
git commit -m "test"
git push -u origin

# 8. 从裸仓库克隆临时工作区,并通过代理完整拉取所有子模块的最新代码
cd "$(dirname "${git_bare_repo}")"
temp_repo="$(mktemp -d -p ./)"
git clone "${git_bare_repo}" "${temp_repo}"
cd "${temp_repo}"
git -c http.proxy=127.0.0.1:10808 submodule update --init --recursive --remote