mcpField
G
git-workflow

git-workflow

github.com/asyrafhussin开发96872 次安装9 周前更新
代码仓库

关于 git-workflow

git-workflow 是面向开发者的 Git 实践指南,涵盖提交、分支、拉取请求、历史管理和协作。它按优先级组织规则,并提供示例与审查问题格式。

主要功能

  1. 01提交信息规范与示例
  2. 02分支命名和策略
  3. 03拉取请求实践
  4. 04历史管理与冲突处理
  5. 05协作与 Git Hooks 指南

适用场景

  1. 01编写清晰一致的提交信息
  2. 02规划分支及发布流程
  3. 03审查并拆分拉取请求
  4. 04整理历史并处理合并冲突

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/asyrafhussin/agent-skills --skill git-workflow

安装后在 Claude Code 中输入/git-workflow确认已加载。

包含的文件

除 SKILL.md 外,安装时一起下载的参考资料和脚本。

AGENTS.md
metadata.json
README.md
rules/
_sections.md
_template.md
branch-delete-merged.md
branch-feature-workflow.md
branch-main-protected.md
branch-monorepo.md
branch-naming-convention.md
branch-release-strategy.md
branch-short-lived.md
branch-workflow-strategies.md
collab-code-review.md
collab-communication.md
collab-conflict-resolution.md
collab-gitignore.md
commit-atomic-changes.md
commit-body-context.md
commit-breaking-changes.md
commit-conventional-format.md
commit-git-hooks.md
commit-imperative-mood.md
commit-meaningful-subject.md
commit-references.md
history-clean-commits.md
history-no-force-push.md
history-rebase-vs-merge.md
history-tags-releases.md
history-worktree.md

详细介绍

Git 工作流

Git 最佳实践、提交约定、分支策略和拉取请求工作流。维护整洁、实用的 Git 历史记录指南。

适用场景

以下情况请参考这些指南:

  • 编写提交消息
  • 创建分支
  • 设置 Git 工作流
  • 审查拉取请求
  • 维护 Git 历史记录

按优先级划分的规则类别

优先级类别影响前缀
1提交消息关键commit-
2分支策略高branch-
3拉取请求高pr-
4历史记录管理中history-
5协作中collab-

快速参考

1. 提交消息(关键)
  • commit-conventional - 使用约定式提交
  • commit-atomic - 原子提交(一个逻辑变更)
  • commit-present-tense - 使用祈使式现在时
  • commit-meaningful - 编写描述清晰、有意义的消息
  • commit-body - 为复杂变更添加正文
  • commit-references - 引用问题/工单
  • commit-git-hooks - 使用 Husky + commitlint 强制执行规范
2. 分支策略(高)
  • branch-naming - 统一分支命名
  • branch-feature - 功能分支工作流
  • branch-main-protected - 保护 main 分支
  • branch-short-lived - 保持分支生命周期较短
  • branch-delete-merged - 删除已合并的分支
  • branch-release - 发布分支策略
  • branch-workflow-strategies - GitFlow、GitHub Flow 与 Trunk-Based 对比
  • branch-monorepo - Monorepo Git 工作流
3. 拉取请求(高)
  • pr-small - 让 PR 保持小而聚焦
  • pr-description - 编写清晰的说明
  • pr-reviewers - 邀请合适的审查者
  • pr-ci-pass - 确保 CI 通过
  • pr-squash - 适时压缩提交
  • pr-draft - 使用草稿 PR 处理进行中的工作并尽早获取反馈
4. 历史记录管理(中)
  • history-rebase - 变基与合并
  • history-no-force-push - 避免强制推送到共享分支
  • history-clean - 保持历史记录整洁
  • history-tags - 使用标签标记发布版本
  • history-worktree - 使用 git worktree 在多个分支上工作
5. 协作(中)
  • collab-code-review - 高效的代码审查
  • collab-conflicts - 处理合并冲突
  • collab-communication - 沟通变更
  • collab-gitignore - .gitignore 最佳实践

核心指南

约定式提交
# Format
<type>(<scope>): <subject>

<body>

<footer>
类型
类型描述
feat新功能
fix修复缺陷
docs仅修改文档
style格式调整,不修改代码
refactor修改代码,但不涉及功能或缺陷修复
perf性能优化
test添加或更新测试
chore维护、依赖项
ciCI/CD 变更
build构建系统变更
revert撤销之前的提交
示例
# ✅ Good commit messages
feat(auth): add password reset functionality

fix(cart): resolve quantity update race condition

docs(readme): add installation instructions

refactor(api): extract validation into middleware

test(user): add unit tests for registration

chore(deps): update dependencies to latest versions

# With body and footer
feat(orders): implement order cancellation

Add ability for users to cancel pending orders within 24 hours.
Cancelled orders trigger refund process automatically.

Closes #123
BREAKING CHANGE: Order status enum now includes 'cancelled'

# ❌ Bad commit messages
fix bug
update
WIP
asdfasdf
changes
misc fixes
分支命名
# ✅ Good branch names
feature/user-authentication
feature/JIRA-123-password-reset
fix/cart-total-calculation
fix/issue-456-login-redirect
hotfix/security-patch
docs/api-documentation
refactor/database-queries
chore/update-dependencies

# ❌ Bad branch names
new-feature
john-branch
test
fix
temp
asdf
分支工作流
# Main branches
main          # Production-ready code
develop       # Integration branch (optional)

# Supporting branches
feature/*     # New features
fix/*         # Bug fixes
hotfix/*      # Production hotfixes
release/*     # Release preparation

# Workflow
git checkout main
git pull origin main
git checkout -b feature/user-profile

# Work on feature...
git add .
git commit -m "feat(profile): add profile page"

# Keep branch updated
git fetch origin
git rebase origin/main

# Push and create PR
git push -u origin feature/user-profile
原子提交
# ❌ One commit doing multiple things
git commit -m "Add login, fix header, update deps"

# ✅ Separate commits for each change
git commit -m "feat(auth): add login page"
git commit -m "fix(header): correct navigation alignment"
git commit -m "chore(deps): update React to v18.2"
频繁提交,定期推送
# ✅ Small, frequent commits
git commit -m "feat(cart): add product to cart"
git commit -m "feat(cart): display cart item count"
git commit -m "feat(cart): implement remove item"
git commit -m "test(cart): add unit tests"

# ❌ One massive commit
git commit -m "feat: implement entire shopping cart"
拉取请求最佳实践
PR 标题
# Format (like commit)
<type>(<scope>): <description>

# ✅ Good PR titles
feat(auth): implement OAuth2 login
fix(checkout): resolve payment processing error
docs(api): add endpoint documentation

# ❌ Bad PR titles
Update
Fix stuff
WIP
PR 描述模板
## Summary
Brief description of what this PR does.

## Changes
- Added user authentication endpoints
- Implemented JWT token generation
- Added password hashing with bcrypt

## Testing
- [ ] Unit tests pass
- [ ] Integration tests pass
- [ ] Manual testing completed

## Screenshots (if UI changes)
[Add screenshots here]

## Related Issues
Closes #123
Related to #456

## Checklist
- [ ] Code follows project conventions
- [ ] Self-review completed
- [ ] Tests added/updated
- [ ] Documentation updated
保持 PR 精简
# ✅ Focused PRs
PR #1: Add user model and migrations
PR #2: Implement user registration endpoint
PR #3: Add email verification
PR #4: Implement login/logout

# ❌ Large unfocused PR
PR #1: Add entire user authentication system
       (2000+ lines, 50+ files)
变基与合并
# ✅ Rebase for feature branches (clean history)
git checkout feature/my-feature
git fetch origin
git rebase origin/main
# Resolve any conflicts
git push --force-with-lease  # Only your branch!

# ✅ Merge for integrating to main (preserve context)
git checkout main
git merge --no-ff feature/my-feature
# Creates merge commit, preserves branch history

# ❌ Never force push to shared branches
git push --force origin main  # NEVER DO THIS
交互式变基(清理)
# Before pushing, clean up commits
git rebase -i HEAD~5

# In editor:
pick abc123 feat: add login page
squash def456 fix typo
squash ghi789 more fixes
pick jkl012 feat: add logout

# Result: clean history with meaningful commits
处理冲突
# During rebase
git rebase origin/main
# CONFLICT in file.ts

# 1. Open conflicted files
# 2. Resolve conflicts (remove markers)
# 3. Stage resolved files
git add file.ts

# 4. Continue rebase
git rebase --continue

# Or abort if needed
git rebase --abort
Git 钩子
# .husky/pre-commit
#!/bin/sh
npm run lint
npm run test:unit

# .husky/commit-msg
#!/bin/sh
npx commitlint --edit $1

# commitlint.config.js
module.exports = {
  extends: ['@commitlint/config-conventional'],
};
标记发布版本
# Semantic versioning tags
git tag -a v1.0.0 -m "Release version 1.0.0"
git push origin v1.0.0

# List tags
git tag -l "v1.*"

# Tag format
v1.0.0    # Major.Minor.Patch
v1.0.0-beta.1  # Pre-release
v1.0.0-rc.1    # Release candidate
.gitignore 最佳实践
# Dependencies
node_modules/
vendor/

# Build outputs
dist/
build/
.next/

# Environment files
.env
.env.local
.env.*.local

# IDE
.idea/
.vscode/
*.swp

# OS files
.DS_Store
Thumbs.db

# Logs
*.log
logs/

# Test coverage
coverage/

# Cache
.cache/
*.cache
实用 Git 命令
# View commit history
git log --oneline --graph --all

# See what changed
git diff --staged
git diff HEAD~1

# Undo last commit (keep changes)
git reset --soft HEAD~1

# Discard local changes
git checkout -- file.ts
git restore file.ts  # Git 2.23+

# Stash changes
git stash
git stash pop
git stash list

# Cherry-pick commit
git cherry-pick abc123

# Find who changed a line
git blame file.ts

# Search commits
git log --grep="fix"
git log -S "functionName"

输出格式

审查 Git 实践时,请输出以下发现:

[category] Description of issue or suggestion

示例:

[commit] Use imperative mood: "Add feature" not "Added feature"
[branch] Branch name 'test' should follow pattern: feature/description
[pr] PR is too large (50+ files), consider splitting

使用方法

阅读各个规则文件,了解详细说明:

rules/commit-conventional-format.md
rules/branch-naming-convention.md
rules/pr-small-focused.md

参考资料

知名项目示例

向采用出色 Git 实践的项目学习:

  • Linux Kernel - 详细的提交消息和补丁工作流
  • React - Conventional Commits 和全面的 PR 审查
  • Vue.js - 清晰的提交历史和完善的 PR 模板
  • TypeScript - 结构化的分支管理和清晰的发布流程
  • Next.js - Conventional Commits 和自动化发布

配置示例

Commitlint
// commitlint.config.js
module.exports = {
  extends: ['@commitlint/config-conventional'],
  rules: {
    'type-enum': [
      2,
      'always',
      ['feat', 'fix', 'docs', 'style', 'refactor', 'perf', 'test', 'chore', 'ci', 'build', 'revert']
    ],
    'subject-max-length': [2, 'always', 72],
    'body-max-line-length': [2, 'always', 100]
  }
};
Husky Git Hooks
# .husky/commit-msg
#!/bin/sh
npx commitlint --edit $1

# .husky/pre-commit
#!/bin/sh
npm run lint
npm test
GitHub PR 模板
# .github/PULL_REQUEST_TEMPLATE.md
## Summary
Brief description of changes

## Changes
- List key changes
- One per line

## Testing
- [ ] Unit tests pass
- [ ] Integration tests pass
- [ ] Manual testing completed

## Related
Closes #issue-number

元数据

技能版本: 1.2.0 最后更新: 2026-03-08 规则总数: 31 类别: 5(提交消息、分支策略、拉取请求、历史管理、协作)

兼容对象:

  • Git 2.0+
  • GitHub、GitLab、Bitbucket、Azure DevOps

推荐工具:


许可证

MIT 许可证。本技能按原样提供,用于教育和开发目的。

评论

支持 Markdown