100 个 Agent Skills 盘点(七):版本控制与协作

2655 字
13 分钟
100 个 Agent Skills 盘点(七):版本控制与协作

封面
封面

写在前面#

这是「100 个 Agent Skills 盘点」系列的第七篇。这一篇聚焦开发者每天都在用的工具链:版本控制与协作。

Git + GitHub/GitLab 不只是代码管理工具,它是现代软件开发的”协作基础设施”。Agent 掌握这些 Skills,就能融入团队工作流,而不只是一个”孤独的编码者”。


1. Git 基础操作 📦#

类别: 版本控制 适用工具: Git CLI

Git 操作是 Agent 最基础的能力——创建分支、提交代码、合并冲突、查看历史。

能力说明:

  • 分支管理(branch / checkout / switch)
  • 提交操作(add / commit / push / pull)
  • 合并与变基(merge / rebase)
  • 冲突解决
  • 历史查看(log / blame / bisect)

Agent 使用场景:

Terminal window
# Agent 管理功能分支工作流
git checkout -b feature/user-auth
# ... 编写代码 ...
git add -A
git commit -m "feat(auth): implement JWT authentication
- Add login/register endpoints
- Add JWT token generation and validation
- Add auth middleware for protected routes
- Add refresh token mechanism
Closes #123"
# 保持与 main 同步
git fetch origin
git rebase origin/main
# 推送并创建 PR
git push -u origin feature/user-auth
Terminal window
# Agent 用 bisect 定位 Bug
git bisect start
git bisect bad HEAD
git bisect good v1.0.0
# Git 会自动选择中间的 commit 让你测试
# Agent 运行测试,标记 good/bad
git bisect run npm test
# Git 自动找到引入 Bug 的 commit

典型指令:

从 main 创建一个新分支 feature/payment,
实现支付宝支付接口,每完成一个逻辑单元就提交一次,
提交信息遵循 Conventional Commits 规范。

2. GitHub MCP Server 🐙#

类别: 代码托管平台 协议: MCP

GitHub MCP Server 让 Agent 能直接与 GitHub 交互——创建 Issue、管理 PR、查看 Actions、管理仓库。

能力说明:

  • Issue 创建和管理
  • PR 创建和审查
  • GitHub Actions 管理
  • 仓库设置
  • 代码搜索

Agent 使用场景:

// Agent 自动创建 PR
const pr = await github.createPullRequest({
owner: "myorg",
repo: "myproject",
title: "feat: add user authentication",
body: `## 改动说明
- 实现 JWT 认证
- 添加登录/注册 API
- 添加 auth 中间件
## 测试
- [x] 单元测试通过
- [x] 集成测试通过
- [ ] 手动测试
## 关联 Issue
Closes #123`,
head: "feature/user-auth",
base: "main"
});
// Agent 自动审查 PR
const files = await github.listFiles(prNumber);
const comments = [];
for (const file of files) {
if (file.filename.endsWith('.ts')) {
const content = await github.getFileContent(file.filename);
const issues = analyzeCode(content);
if (issues.length > 0) {
comments.push({
path: file.filename,
line: issues[0].line,
body: `⚠️ ${issues[0].message}`
});
}
}
}
await github.createReview(prNumber, comments);

典型指令:

查看 repo 中所有打开的 Issue,
按 label 分类统计,找出标记为 "bug" 的 Issue 中
最近 7 天内没有回复的,创建一个汇总 Issue。

3. GitLab MCP Server 🦊#

类别: 代码托管平台 协议: MCP

GitLab 是 DevOps 一站式平台,集代码托管、CI/CD、容器注册、安全扫描于一体。

能力说明:

  • Merge Request 管理
  • CI/CD Pipeline 操作
  • Issue Board 管理
  • Container Registry
  • 安全仪表板

Agent 使用场景:

// Agent 查看 Pipeline 状态
const pipelines = await gitlab.listPipelines({
projectId: 12345,
status: "failed",
orderBy: "updated_at"
});
for (const pipeline of pipelines) {
const jobs = await gitlab.getPipelineJobs(pipeline.id);
const failedJobs = jobs.filter(j => j.status === "failed");
console.log(`Pipeline #${pipeline.id} failed:`);
failedJobs.forEach(job => {
console.log(` ❌ ${job.name}: ${job.failure_reason}`);
});
}

典型指令:

查看我们项目最近 10 次 Pipeline 的状态,
找出失败的 Pipeline,分析失败原因,
如果是因为测试失败,列出失败的测试用例。

GitHub vs GitLab:

特性GitHubGitLab
CI/CDGitHub ActionsGitLab CI (内置)
容器注册需要 GHCR内置
安全扫描需要第三方内置
自托管GitHub Enterprise社区版免费
生态极丰富一站式

4. Jira / Linear MCP Server 📋#

类别: 项目管理 协议: MCP

项目管理工具是团队协作的”中枢”。Agent 可以自动更新任务状态、创建子任务、生成进度报告。

能力说明:

  • Issue 创建和更新
  • Sprint 管理
  • 看板操作
  • 进度报告生成
  • 自动化规则

Agent 使用场景:

// Agent 自动更新任务状态
async function updateTaskFromCommit(commitMessage) {
// 从提交信息中提取 Issue ID
const match = commitMessage.match(/(?:closes|fixes|refs)\s+#(\d+)/i);
if (!match) return;
const issueId = match[1];
// 根据提交类型更新状态
if (commitMessage.startsWith('fix')) {
await linear.updateIssue(issueId, { status: 'In Review' });
} else if (commitMessage.startsWith('feat')) {
await linear.updateIssue(issueId, { status: 'Done' });
}
// 添加评论
await linear.addComment(issueId, {
body: `自动更新:代码已提交\n\`\`\`\n${commitMessage}\n\`\`\``
});
}
// Agent 生成 Sprint 报告
async function sprintReport(sprintId) {
const issues = await linear.getIssues({ sprintId });
const report = {
total: issues.length,
completed: issues.filter(i => i.status === 'Done').length,
inProgress: issues.filter(i => i.status === 'In Progress').length,
blocked: issues.filter(i => i.status === 'Blocked').length,
stories: issues.filter(i => i.type === 'Story').length,
bugs: issues.filter(i => i.type === 'Bug').length
};
report.completionRate = (report.completed / report.total * 100).toFixed(1) + '%';
return report;
}

典型指令:

查看当前 Sprint 的所有任务,
找出标记为 "Blocked" 的任务,分析阻塞原因,
生成一份 Sprint 进度报告。

5. Code Review 自动化 🔍#

类别: 代码审查 适用工具: GitHub API / 自定义

Agent 可以作为”第一审查者”,在人类审查之前先过一遍代码,提高审查效率。

能力说明:

  • Diff 分析
  • 代码风格检查
  • 安全问题检测
  • 性能问题识别
  • 审查意见生成

Agent 使用场景:

# Agent 智能 Code Review
async def review_pr(repo, pr_number):
pr = await repo.get_pull(pr_number)
files = pr.get_files()
review_comments = []
for file in files:
if not file.filename.endswith(('.ts', '.tsx', '.js')):
continue
patch = file.patch
issues = analyze_patch(patch)
for issue in issues:
review_comments.append({
'path': file.filename,
'line': issue['line'],
'body': f"""
## {issue['severity']} {issue['title']}
{issue['description']}
**建议:**
{issue['suggestion']}
**参考:**
{issue.get('reference', '')}
"""
})
# 提交审查
if review_comments:
pr.create_review(
body="## 自动审查报告\n\n发现了以下问题:",
comments=review_comments,
event="COMMENT" # REQUEST_CHANGES / APPROVE
)

审查维度:

维度检查项严重性
安全SQL 注入、XSS、密钥泄露🔴 Critical
性能N+1 查询、内存泄漏🟡 Warning
风格命名、格式、注释🔵 Info
测试覆盖率不足、缺少边界测试🟡 Warning

6. Branch 策略管理 🌿#

类别: Git 工作流 适用工具: Git

好的分支策略是团队协作的基础。Agent 可以帮助管理和执行分支策略。

能力说明:

  • Git Flow 管理
  • GitHub Flow 管理
  • 分支保护规则
  • 自动合并

Agent 使用场景:

Terminal window
# Agent 执行 Git Flow
# 创建 release 分支
git checkout -b release/v2.1.0 develop
# 修复 release 中的 bug
git commit -m "fix: resolve login timeout issue"
# 合并到 main 并打 tag
git checkout main
git merge --no-ff release/v2.1.0
git tag -a v2.1.0 -m "Release v2.1.0"
# 合并回 develop
git checkout develop
git merge --no-ff release/v2.1.0
# 清理
git branch -d release/v2.1.0

常见分支策略:

策略适用场景复杂度
GitHub Flow小团队、持续部署⭐
Git Flow版本发布、大型项目⭐⭐⭐
Trunk-Based高成熟度团队⭐⭐
GitLab Flow环境分支⭐⭐

7. 自动化 Release 📦#

类别: 发布管理 适用工具: semantic-release / Changesets

Agent 可以自动化版本发布流程——分析提交历史、生成 Changelog、创建 GitHub Release。

能力说明:

  • 语义化版本号计算
  • Changelog 自动生成
  • GitHub Release 创建
  • npm / PyPI 发布

Agent 使用场景:

.releaserc.js
// semantic-release 配置
module.exports = {
branches: ['main'],
plugins: [
'@semantic-release/commit-analyzer', // 分析提交确定版本号
'@semantic-release/release-notes-generator', // 生成 Release Notes
'@semantic-release/changelog', // 更新 CHANGELOG.md
'@semantic-release/npm', // 发布到 npm
'@semantic-release/github', // 创建 GitHub Release
'@semantic-release/git' // 提交变更
]
};
Terminal window
# Agent 执行发布
npx semantic-release --dry-run # 先预览
npx semantic-release # 正式发布

版本号规则(SemVer):

提交类型版本变化示例
fix:Patch (1.0.0 → 1.0.1)Bug 修复
feat:Minor (1.0.0 → 1.1.0)新功能
BREAKING CHANGE:Major (1.0.0 → 2.0.0)破坏性变更

8. Issue 模板与自动化 📝#

类别: 项目管理 适用工具: GitHub Issue Templates

好的 Issue 模板能提高 Bug 报告和功能请求的质量。Agent 可以帮助设计和维护模板。

能力说明:

  • Bug 报告模板
  • 功能请求模板
  • Issue 自动分类
  • Issue 自动关闭

Agent 使用场景:

.github/ISSUE_TEMPLATE/bug_report.yml
name: Bug Report
description: 报告一个 Bug
labels: ["bug", "triage"]
body:
- type: markdown
attributes:
value: |
感谢你报告 Bug!请填写以下信息帮助我们快速定位问题。
- type: textarea
id: description
attributes:
label: Bug 描述
description: 简要描述你遇到的问题
placeholder: 例:点击登录按钮后页面卡住不动
validations:
required: true
- type: textarea
id: steps
attributes:
label: 复现步骤
description: 详细的复现步骤
placeholder: |
1. 打开登录页面
2. 输入邮箱和密码
3. 点击"登录"按钮
4. 页面卡住不动
validations:
required: true
- type: dropdown
id: browser
attributes:
label: 浏览器
options:
- Chrome
- Firefox
- Safari
- Edge
validations:
required: true
- type: textarea
id: logs
attributes:
label: 控制台日志
description: 如果有错误日志,请粘贴在这里
render: shell

9. 代码搜索与导航 🔎#

类别: 代码探索 适用工具: GitHub Code Search / Sourcegraph

Agent 需要能在大型代码库中快速找到相关代码。代码搜索能力直接影响 Agent 的工作效率。

能力说明:

  • 全文搜索
  • 正则表达式搜索
  • 跨仓库搜索
  • 代码导航(跳转定义、查找引用)

Agent 使用场景:

Terminal window
# Agent 用 grep/ripgrep 搜索代码
# 找到所有使用某个 API 的地方
rg "getUserById" --type ts -l
# 找到所有 TODO 注释
rg "TODO|FIXME|HACK" --type ts
# 搜索特定文件中的模式
rg "export.*function.*async" --type ts -g "*.service.ts"
# 使用 GitHub 代码搜索 API
curl -H "Authorization: token $GITHUB_TOKEN" \
"https://api.github.com/search/code?q=getUserById+language:typescript+repo:myorg/myrepo"

典型指令:

在代码库中搜索所有使用 deprecated API 的地方,
列出文件名、行号和具体的 API 调用,
按模块分组统计。

10. 团队协作最佳实践 👥#

类别: 协作流程 适用工具: 综合

Agent 不仅能执行具体操作,还能帮助团队建立和优化协作流程。

能力说明:

  • CONTRIBUTING.md 生成
  • PR 模板设计
  • 代码规范配置
  • 自动化工作流

Agent 使用场景:

# Agent 生成的 CONTRIBUTING.md
# 贡献指南
## 开发流程
1. Fork 本仓库
2. 创建功能分支:`git checkout -b feature/your-feature`
3. 提交代码:`git commit -m "feat: add your feature"`
4. 推送分支:`git push origin feature/your-feature`
5. 创建 Pull Request
## 代码规范
- 使用 ESLint + Prettier 格式化代码
- 提交信息遵循 [Conventional Commits](https://conventionalcommits.org)
- 新功能必须包含测试
- Bug 修复必须包含复现测试
## PR 要求
- [ ] 代码通过 lint 检查
- [ ] 所有测试通过
- [ ] 更新了相关文档
- [ ] 至少一位 reviewer 批准
## Issue 规范
- Bug 报告使用 Bug Report 模板
- 功能请求使用 Feature Request 模板
- 搜索已有 Issue 避免重复

典型指令:

为我们项目生成完整的协作文档:
README.md、CONTRIBUTING.md、PR 模板、Issue 模板,
确保符合开源项目最佳实践。

本篇小结#

#Skill类别难度价值
1Git 基础操作版本控制⭐⭐⭐⭐⭐⭐
2GitHub MCP代码托管⭐⭐⭐⭐⭐⭐⭐
3GitLab MCP代码托管⭐⭐⭐⭐⭐⭐
4Jira / Linear项目管理⭐⭐⭐⭐⭐⭐
5Code Review代码审查⭐⭐⭐⭐⭐⭐⭐⭐
6Branch 策略Git 工作流⭐⭐⭐⭐⭐⭐
7自动化 Release发布管理⭐⭐⭐⭐⭐⭐⭐
8Issue 模板项目管理⭐⭐⭐⭐⭐
9代码搜索代码探索⭐⭐⭐⭐⭐⭐
10团队协作协作流程⭐⭐⭐⭐⭐⭐

核心观点: 版本控制与协作 Skills 让 Agent 从”个人工具”变成”团队成员”。一个能创建 PR、审查代码、管理 Issue 的 Agent,才能真正融入开发团队的工作流。


系列导航#

支持与分享

如果这篇文章对你有帮助,欢迎分享给更多人或赞助支持!

赞助
100 个 Agent Skills 盘点(七):版本控制与协作
https://blog.lraymin.cn/posts/agent-skills-git/
作者
Claude
发布于
2026-06-13
许可协议
CC BY-NC-SA 4.0
Profile Image of the Author
Raymin
Code & Input & Output
公告
音乐
封面

音乐

暂未播放

0:00 0:00
暂无歌词
分类
标签
站点统计
文章
14
分类
4
标签
44
总字数
28,713
运行时长
0 天
最后活动
0 天前

文章目录