git-workflow
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseGit Workflow
Git 工作流
Standardized Git workflow for commits, pull requests, and releases using conventional commits format and semantic versioning.
基于约定式提交(conventional commits)格式和语义化版本控制(semantic versioning)的标准化Git工作流,适用于提交、拉取请求和版本发布场景。
Prerequisites
前置条件
| Tool | Type | Required | Install |
|---|---|---|---|
| git | cli | Yes | |
| gh | cli | No | |
Do NOT proactively verify these tools on skill load. If a command fails due to a missing tool, directly guide the user through installation and configuration step by step.
| 工具 | 类型 | 是否必需 | 安装方式 |
|---|---|---|---|
| git | 命令行工具 | 是 | |
| gh | 命令行工具 | 否 | |
请勿在技能加载时主动验证这些工具。如果因缺少工具导致命令失败,请直接逐步引导用户完成安装和配置。
When to Use
适用场景
- Creating commits: Follow conventional commits with concise, imperative messages
- Creating pull requests: Generate PR with clear description and test plan
- Creating releases: Update versions, CHANGELOG, tags, and GitHub releases
These workflows can be used independently or together as needed.
- 创建提交:遵循约定式提交规范,使用简洁的祈使句消息
- 创建拉取请求(PR):生成包含清晰描述和测试计划的PR
- 创建版本发布:更新版本号、CHANGELOG、标签和GitHub版本发布
这些工作流可根据需要独立使用或组合使用。
Platform Detection
平台检测
Check to select workflow:
git remote get-url origin| Remote URL contains | Commits/Tags/Releases | PR/MR |
|---|---|---|
| This skill | This skill ( |
| This skill | Switch to |
| This skill | This skill (adapt for GitLab CLI) |
通过执行命令判断远程仓库地址,选择对应的工作流:
git remote get-url origin| 远程URL包含 | 提交/标签/版本发布 | PR/MR |
|---|---|---|
| 使用本技能 | 使用本技能( |
| 使用本技能 | 切换至 |
| 使用本技能 | 使用本技能(适配GitLab CLI) |
Quick Reference
快速参考
Commit Format
提交格式
text
type(scope): concise summary
- Optional bullet points (max 3-4)
- Keep short and focusedTypes: feat, fix, refactor, docs, test, chore
text
type(scope): 简洁摘要
- 可选项目符号(最多3-4条)
- 保持简短且聚焦类型:feat(新功能)、fix(修复)、refactor(重构)、docs(文档)、test(测试)、chore(杂项)
Branch Naming
分支命名规范
feature/descriptionfix/descriptiondocs/descriptionrefactor/descriptiontest/description
feature/描述内容fix/描述内容docs/描述内容refactor/描述内容test/描述内容
Release Checklist
版本发布检查清单
- Update version in project files
- Update CHANGELOG.md
- Commit:
chore(release): bump version to x.y.z - Tag:
git tag v{version} && git push upstream v{version} - Create GitHub release with
gh release create
- 更新项目文件中的版本号
- 更新CHANGELOG.md
- 提交:
chore(release): bump version to x.y.z - 打标签:
git tag v{version} && git push upstream v{version} - 使用创建GitHub版本发布
gh release create
Default Behaviors
默认行为
- Keep messages concise: Commit messages and PR titles must be short and to the point. Omit filler words. The diff shows "what" — the message explains "why".
- No AI signatures: Never include ,
Co-Authored-By: Claude, or any AI markers in commits or PRs.Generated with Claude Code - Commit always pushes: After commit, always push immediately. Do not ask.
- Has upstream tracking →
git push - No upstream tracking →
git push -u origin <branch>
- Has upstream tracking →
- 保持消息简洁:提交消息和PR标题必须简短明了,省略冗余词汇。代码差异展示“做了什么”,消息则解释“为什么这么做”。
- 无AI签名:请勿在提交或PR中包含、
Co-Authored-By: Claude或任何AI标记。Generated with Claude Code - 提交后立即推送:提交完成后立即推送,无需询问。
- 已设置上游跟踪 → 执行
git push - 未设置上游跟踪 → 执行
git push -u origin <branch>
- 已设置上游跟踪 → 执行
Detailed Guides
详细指南
See examples-and-templates.md for commit examples (good/bad), PR body template, and CHANGELOG format.
请查看examples-and-templates.md获取提交示例(正确/错误示范)、PR正文模板和CHANGELOG格式说明。
Validation
验证方式
Use to validate commit messages:
scripts/validate_commit.pybash
python3 scripts/validate_commit.py "feat(auth): add OAuth2 support"
python3 scripts/validate_commit.py --file .git/COMMIT_EDITMSGThe validator checks:
- Conventional commits format
- Subject line length (< 72 chars)
- Imperative mood usage
- Absence of AI-generated markers
- Body format and bullet point count
使用脚本验证提交消息格式:
scripts/validate_commit.pybash
python3 scripts/validate_commit.py "feat(auth): add OAuth2 support"
python3 scripts/validate_commit.py --file .git/COMMIT_EDITMSG验证脚本会检查以下内容:
- 约定式提交格式是否合规
- 主题行长度(<72字符)
- 是否使用祈使语气
- 是否存在AI生成标记
- 正文格式和项目符号数量
Common Workflows
常见工作流
Commit (default: commit + push)
提交(默认:提交 + 推送)
bash
git add <files>
git commit -m "feat(component): add new feature" && git pushbash
git add <files>
git commit -m "feat(component): add new feature" && git pushPull Request
拉取请求(PR)
bash
git checkout -b feature/new-featurebash
git checkout -b feature/new-feature... make changes, commit (auto-pushes per default behavior) ...
... 进行代码修改,提交(按默认行为自动推送) ...
gh pr create --title "feat(component): add new feature" --body "..."
undefinedgh pr create --title "feat(component): add new feature" --body "..."
undefinedRelease
版本发布
bash
undefinedbash
undefinedUpdate version files + CHANGELOG.md
更新版本文件和CHANGELOG.md
git add .
git commit -m "chore(release): bump version to 1.2.0" && git push
git tag v1.2.0 && git push upstream v1.2.0
gh release create v1.2.0 -R owner/repo --title "v1.2.0" --notes "..."
undefinedgit add .
git commit -m "chore(release): bump version to 1.2.0" && git push
git tag v1.2.0 && git push upstream v1.2.0
gh release create v1.2.0 -R owner/repo --title "v1.2.0" --notes "..."
undefinedCommon Issues
常见问题
| Issue | Cause | Fix |
|---|---|---|
| Subject line > 72 chars | Description too long | Shorten summary, put details in body |
| Multiple types in one commit | Scope too large | Split into single-purpose commits |
| Merge commits appear | Used merge | Use |
| Validator script errors | Format mismatch | Check type(scope): format |
| 问题 | 原因 | 解决方法 |
|---|---|---|
| 主题行长度超过72字符 | 描述过于冗长 | 精简摘要,将细节放在正文中 |
| 单个提交包含多种类型 | 范围过大 | 拆分为单一目的的提交 |
| 出现合并提交 | 使用了合并操作 | 使用 |
| 验证脚本报错 | 格式不匹配 | 检查是否符合 |