Git version control best practices including branching strategies, commit conventions, merge strategies, and conflict resolution. Use when: managing branches, creating commits, merging code, resolving conflicts, creating PRs, or code review workflows. Auto-activates when users mention: git, commit, branch, merge, rebase, cherry-pick, PR, pull request, conflict, stash, gitflow, conventional commits.
View on GitHubskills/git/SKILL.md
February 2, 2026
Select agents to install to:
npx add-skill https://github.com/xiaobei930/claude-code-best-practices/blob/main/skills/git/SKILL.md -a claude-code --skill gitInstallation paths:
.claude/skills/git/# Git 工作流技能
本技能提供 Git 版本控制的最佳实践。
## 触发条件
- 管理 Git 分支
- 创建提交
- 处理合并
- 解决冲突
- 代码审查
## Workflow | 工作流程
### 1. 检查当前状态
```bash
git status
git branch -a
git log --oneline -5
```
根据状态确定下一步操作。
### 2. 选择操作类型
| 场景 | 执行流程 |
| ------------ | ------------------------------------------- |
| 创建功能分支 | `git checkout -b feature/xxx` → 开发 → 提交 |
| 提交代码 | `git add` → `git commit` → 验证 |
| 合并代码 | `git checkout main` → `git merge` → 推送 |
| 解决冲突 | 查看冲突 → 手动解决 → 标记解决 → 继续 |
| 创建 PR | 推送分支 → `gh pr create` → 等待审查 |
### 3. 执行并验证
- 执行命令前确认当前分支和状态
- 执行后验证结果:`git status`, `git log --oneline -3`
- 确保无未提交的修改或冲突
### 4. 完成确认
```
✅ Git 操作完成!
📊 当前状态:
分支: [当前分支名]
最新提交: [commit message]
⚠️ 提醒:
- 功能完成后记得创建 PR
- 合并前确保通过所有测试
- 定期从 main 分支同步更新
```
## 分支策略
### 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 |
### 示例
```b