Use when setting up or installing the automated GitLab git workflow in a project, including branch versioning, monthly tags, auto-merge to develop, and branch cleanup.
65
82%
Does it follow best practices?
Impact
—
No eval scenarios have been run
Passed
No known issues
为 GitLab 项目提供一套完整的自动化 Git 工作流,基于语义化版本管理,支持多人协作。
核心规则:
develop(开发集成)、release(测试)、master(生产,人工管理)| 类型 | 格式 | 示例 |
|---|---|---|
| 月度 tag | V{major}.{minor}.{patch} | V2.0.1 |
| base 分支 | V{x.y.z}_base_{username} | V2.0.1_base_liwanchun |
| 子版本分支 | V{x.y.z}.{n}_{username} | V2.0.1.3_liwanchun |
版本进位:patch 满9进位(V2.0.9 → V2.1.0,V2.9.9 → V3.0.0)
将技能目录下的文件复制到项目:
skills/gitlab-gitflow/scripts/ → 项目 scripts/gitflow/
skills/gitlab-gitflow/templates/.gitflow-members → 项目根目录
skills/gitlab-gitflow/templates/gitlab-ci-gitflow.yml → 追加到项目 .gitlab-ci.yml具体命令(在项目根目录执行):
mkdir -p scripts/gitflow
cp ~/.claude/skills/gitlab-gitflow/scripts/*.sh scripts/gitflow/
cp ~/.claude/skills/gitlab-gitflow/templates/.gitflow-members ..gitattributes 处理(Windows 必须,防止 CRLF 导致脚本报错):
.gitattributes:直接复制模板.gitattributes:追加以下内容:
scripts/gitflow/*.sh text eol=lf.gitlab-ci.yml 处理:
.gitlab-ci.yml:直接复制模板.gitlab-ci.yml:将模板内容追加到末尾编辑 .gitflow-members,每行填写一个成员的 git username(不含空格):
liwanchun
zhangsanSettings → CI/CD → Variables 添加 ACCESS_TOKEN
write_repository 权限Settings → CI/CD → Schedules 新建定时任务
0 0 1 * *,分支选 master,勾选 Active# 在 master 分支上手动执行一次月度初始化
bash scripts/gitflow/monthly.sh --force# 1. 配置 git 凭证永久保存(只需执行一次,之后 push 不再弹出账号密码)
git config --global credential.helper store
# 2. 安装 post-commit hook
bash scripts/gitflow/install-hooks.sh执行完后第一次 push 时输入一次账号密码,之后永久免密。
git checkout V2.0.1_base_liwanchun
# 修改代码...
git add .
git commit -m "feat: xxx"
# hook 自动触发:创建 V2.0.1.N_liwanchun → 合并到 developbash scripts/gitflow/add-member.sh <username>
# 自动:基于当前 tag 创建 base 分支,追加到 .gitflow-members
# 手动:提交 .gitflow-members 变更develop → release(提测)→ master(你手动合并)
master 有新 push → GitLab CI 自动清理已合入的子版本分支| 脚本 | 触发方式 | 作用 |
|---|---|---|
post-commit.sh | 本地 commit hook | 创建子版本分支,合并到 develop |
monthly.sh | GitLab CI 定��(每月1号) | 打 tag,创建 base 分支,清理旧 base |
cleanup-merged.sh | GitLab CI(master push 时) | 删除已合入 master 的子版本分支 |
install-hooks.sh | 开发者手动执行一次 | 安装本地 post-commit hook |
add-member.sh <username> | 手动执行 | 月中新增成员,不影响已有分支 |
monthly.sh 有日期保护,非1号执行会报错(加 --force 可绕过)