CtrlK
BlogDocsLog inGet started
Tessl Logo

yes-or-no/gitlab-commitflow

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

Quality

82%

Does it follow best practices?

Run evals on this skill

Adds up to 20 points to the overall score

View guide

SecuritybySnyk

Passed

No findings from the security scan

Overview
Quality
Evals
Security
Files
name:
gitlab-commitflow
description:
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.

GitLab 自动化工作流

概述

为 GitLab 项目提供一套完整的自动化 Git 工作流,基于语义化版本管理,支持多人协作。

核心规则:

  • 固定分支:develop(开发集成)、release(测试)、master(生产,人工管理)
  • 每月1号自动打 tag、创建 base 分支
  • 每次 commit 自动创建子版本分支并合并到 develop
  • 合入 master 后自动清理子版本分支

分支命名规范

类型格式示例
月度 tagV{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
zhangsan

第三步:GitLab 配置(管理员操作)

  1. Settings → CI/CD → Variables 添加 ACCESS_TOKEN
    • Personal Access Token,需要 write_repository 权限
  2. Settings → CI/CD → Schedules 新建定时任务
    • Cron: 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 → 合并到 develop

月中新增成员

bash 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.shGitLab CI 定��(每月1号)打 tag,创建 base 分支,清理旧 base
cleanup-merged.shGitLab CI(master push 时)删除已合入 master 的子版本分支
install-hooks.sh开发者手动执行一次安装本地 post-commit hook
add-member.sh <username>手动执行月中新增成员,不影响已有分支

注意事项

  • monthly.sh 有日期保护,非1号执行会报错(加 --force 可绕过)
  • 子版本分支跨月未合入 master 会一直保留,不会被误删
  • base 分支月初自动清理,子版本分支只在进入 master 后清理
  • Windows 开发者需使用 Git Bash 执行脚本
Workspace
yes-or-no
Visibility
Public
Created
Last updated
Publish Source
CLI
Badge
yes-or-no/gitlab-commitflow badge