Back to Skills

git-workflow

verified

Git branching strategies, commit conventions, merge strategies, conflict resolution. Use when managing branches, creating commits, or resolving conflicts.

View on GitHub

Marketplace

claude-code-best-practices

xiaobei930/claude-code-best-practices

Plugin

cc-best

Repository

xiaobei930/claude-code-best-practices
1stars

skills/git-workflow/SKILL.md

Last Verified

January 25, 2026

Install Skill

Select agents to install to:

Scope:
npx add-skill https://github.com/xiaobei930/claude-code-best-practices/blob/main/skills/git-workflow/SKILL.md -a claude-code --skill git-workflow

Installation paths:

Claude
.claude/skills/git-workflow/
Powered by add-skill CLI

Instructions

# Git 工作流技能

本技能提供 Git 版本控制的最佳实践。

## 触发条件

- 管理 Git 分支
- 创建提交
- 处理合并
- 解决冲突
- 代码审查

## 分支策略

### Git Flow

```
main (生产)
  │
  └── develop (开发)
        │
        ├── feature/xxx (功能分支)
        ├── release/x.x (发布分支)
        └── hotfix/xxx (热修复)
```

### GitHub Flow(推荐)

```
main (始终可部署)
  │
  └── feature/xxx (功能分支)
        │
        └── PR → Code Review → Merge
```

### 分支命名规范

```bash
# 功能分支
feature/add-user-auth
feature/JIRA-123-payment-integration

# Bug 修复
fix/login-validation
bugfix/JIRA-456-cart-total

# 热修复
hotfix/security-patch

# 发布
release/v1.2.0

# 重构
refactor/database-layer
```

## 提交规范 (Conventional Commits)

### 格式

```
<type>(<scope>): <subject>

<body>

<footer>
```

### 类型

| 类型     | 说明      | 示例                         |
| -------- | --------- | ---------------------------- |
| feat     | 新功能    | feat(auth): 添加 OAuth 登录  |
| fix      | Bug 修复  | fix(cart): 修复价格计算错误  |
| docs     | 文档更新  | docs(readme): 更新安装说明   |
| style    | 格式调整  | style: 格式化代码            |
| refactor | 重构      | refactor(api): 重构用户服务  |
| perf     | 性能优化  | perf(query): 优化搜索查询    |
| test     | 测试      | test(user): 添加用户注册测试 |
| chore    | 构建/工具 | chore(deps): 更新依赖        |
| ci       | CI 配置   | ci: 添加 GitHub Actions      |

### 示例

```bash
# 简单提交
git commit -m "feat(user): 添加用户头像上传功能"

# 带详情的提交
git commit -m "fix(payment): 修复支付金额精度问题

- 使用 Decimal 替代 float 处理金额
- 添加金额格式化工具函数
- 更新相关测试用例

Closes #123"

# 破坏性变更
git commit -m "feat(api)!: 重构 API 响应格式

BREAKING CHANGE: API 响应格式从 {data} 改为 {success, data, error}"
```

## 常用命令

### 分支操作

```bash
# 创建并切换分支
git checkout -b feature/new-feature

# 从远程创建本地分支
git checkout -b feature/xxx origin/feature/xxx

# 删除本地分支
git branch -d feature/xxx

# 删除远程分支
git push origin --delete feature/xxx

# 重命名分支
git branch -m old-name new-name
```

### 提交操作

```bash
# 暂存特定文件
git add src/user.ts src/auth.ts

# 交互式暂存
git add -p

# 修改最后一次提交(未推送)
git commit --amend

# 修改提交信息
git commit --amend -m "新的提交信息"
```

### 同步操作

```bash
# 拉取并变基
git pull --rebase ori

Validation Details

Front Matter
Required Fields
Valid Name Format
Valid Description
Has Sections
Allowed Tools
Instruction Length:
4939 chars