sync_to_github
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chinesesync_to_github
sync_to_github
Automatically analyze project changes, generate descriptive commit messages using AI, and commit to git.
自动分析项目变更,使用AI生成描述性提交信息,并提交至Git。
Purpose
用途
This skill automates the git workflow by:
- Analyzing current git status (staged and unstaged changes)
- Generating descriptive commit messages based on change content
- Creating commits with AI-generated messages
- Optionally pushing to remote repository
本Skill通过以下方式自动化Git工作流:
- 分析当前Git状态(已暂存和未暂存的变更)
- 根据变更内容生成描述性提交信息
- 使用AI生成的信息创建提交
- 可选推送至远程仓库
Input/Output Contract
输入/输出约定
Input
输入
- No required parameters
- Optional flags:
- : Automatically push to remote after committing
--push - : Preview commit message without committing
--dry-run
- 无必填参数
- 可选标志:
- :提交后自动推送至远程仓库
--push - :预览提交信息但不实际提交
--dry-run
Output
输出
- Git commit created with descriptive message
- Optional: Push to remote repository
- Console output showing:
- Files changed
- Generated commit message
- Commit hash
- 已创建带有描述性信息的Git提交
- 可选:推送至远程仓库
- 控制台输出内容包括:
- 已变更文件
- 生成的提交信息
- 提交哈希值
Dependencies
依赖项
- Git (command line)
- Python 3.x
- Working git repository with commits
- Git(命令行工具)
- Python 3.x
- 包含提交记录的可用Git仓库
Usage
使用方法
Basic Usage
基础用法
bash
undefinedbash
undefinedAnalyze changes and create commit
分析变更并创建提交
Skill(sync_to_github)
Skill(sync_to_github)
Commit and push to remote
提交并推送至远程仓库
Skill(sync_to_github, args="--push")
Skill(sync_to_github, args="--push")
Preview without committing
预览提交信息但不实际提交
Skill(sync_to_github, args="--dry-run")
undefinedSkill(sync_to_github, args="--dry-run")
undefinedExamples
示例
Example 1: Feature Development
示例1:功能开发
bash
undefinedbash
undefinedAfter implementing a new feature
完成新功能实现后
Skill(sync_to_github)
Output:Analyzing changes...
Files modified:
src/components/Button.tsx
src/styles/button.css
Generated commit message:
feat: add Button component with hover states
- Add reusable Button component with props interface
- Implement hover and active state animations
- Add CSS module for button styling
Commit created: abc123def
undefinedSkill(sync_to_github)
输出:正在分析变更...
已修改文件:
src/components/Button.tsx
src/styles/button.css
生成的提交信息:
feat: add Button component with hover states
- 新增带有props接口的可复用Button组件
- 实现悬停和激活状态动画
- 添加用于按钮样式的CSS模块
已创建提交:abc123def
undefinedExample 2: Bug Fix
示例2:Bug修复
bash
undefinedbash
undefinedAfter fixing a bug
修复Bug后
Skill(sync_to_github, args="--push")
Output:Analyzing changes...
Files modified:
src/utils/api.ts
tests/api.test.ts
Generated commit message:
fix: resolve API timeout error in data fetching
- Increase timeout from 5s to 30s for slow endpoints
- Add retry logic with exponential backoff
- Update test coverage for timeout scenarios
Commit created: 456789ghi
Pushed to origin/main
undefinedSkill(sync_to_github, args="--push")
输出:正在分析变更...
已修改文件:
src/utils/api.ts
tests/api.test.ts
生成的提交信息:
fix: resolve API timeout error in data fetching
- 将慢接口的超时时间从5秒增加至30秒
- 添加带指数退避的重试逻辑
- 更新超时场景的测试覆盖率
已创建提交:456789ghi
已推送至origin/main
undefinedExample 3: Documentation Update
示例3:文档更新
bash
undefinedbash
undefinedAfter updating documentation
更新文档后
Skill(sync_to_github)
Output:Analyzing changes...
Files modified:
README.md
docs/api.md
docs/examples.md
Generated commit message:
docs: update API documentation with new endpoints
- Add new authentication endpoint examples
- Clarify rate limiting behavior
- Fix broken links in API reference
Commit created: def123ghi
undefinedSkill(sync_to_github)
输出:正在分析变更...
已修改文件:
README.md
docs/api.md
docs/examples.md
生成的提交信息:
docs: update API documentation with new endpoints
- 添加新的认证端点示例
- 明确速率限制规则
- 修复API参考中的失效链接
已创建提交:def123ghi
undefinedImplementation
实现细节
The skill uses the Python tool at which:
tools/git_sync.py-
Analyzes git statusbash
git status --porcelain git diff --cached git diff -
Generates commit message
- Categorizes change type (feat/fix/docs/refactor/test/chore)
- Summarizes main changes in title
- Lists specific changes in bullet points
- Follows conventional commits format
-
Creates commitbash
git add . git commit -m "<generated message>" -
Optional pushbash
git push
本Skill使用位于的Python工具,具体流程如下:
tools/git_sync.py-
分析Git状态bash
git status --porcelain git diff --cached git diff -
生成提交信息
- 分类变更类型(feat/fix/docs/refactor/test/chore等)
- 在标题中总结主要变更
- 用项目符号列出具体变更内容
- 遵循规范化提交格式
-
创建提交bash
git add . git commit -m "<generated message>" -
可选推送bash
git push
Commit Message Format
提交信息格式
Follows conventional commits specification:
<type>(<scope>): <subject>
<body>
<footer>Types:
- : New feature
feat - : Bug fix
fix - : Documentation changes
docs - : Code style changes (formatting)
style - : Code refactoring
refactor - : Adding or updating tests
test - : Maintenance tasks
chore - : Performance improvements
perf
遵循规范化提交规范:
<type>(<scope>): <subject>
<body>
<footer>类型说明:
- :新功能
feat - :Bug修复
fix - :文档变更
docs - :代码样式变更(格式化)
style - :代码重构
refactor - :添加或更新测试
test - :维护任务
chore - :性能优化
perf
Error Handling
错误处理
No Changes Detected
未检测到变更
Error: No changes to commit
Working directory is clean. Make some changes before running sync_to_github.错误:无变更可提交
工作目录已干净。请先进行一些变更再运行sync_to_github。Git Repository Not Found
未找到Git仓库
Error: Not a git repository
Initialize with: git init错误:当前目录不是Git仓库
请先初始化:git initNothing Staged
无暂存内容
The skill automatically stages all changes with
git add .本Skill会自动使用暂存所有变更
git add .Push Fails
推送失败
Warning: Commit created but push failed
Commit hash: abc123def
Error: <git error message>
Manual push required: git push警告:已创建提交但推送失败
提交哈希:abc123def
错误:<Git错误信息>
需要手动推送:git pushIntegration
集成
Permissions
权限配置
Add to :
.claude/settings.local.jsonjson
{
"permissions": {
"allow": [
"Skill(sync_to_github)",
"Bash(python3:.claude/skills/sync_to_github/tools/*)",
"Bash(git:*)"
]
}
}添加至:
.claude/settings.local.jsonjson
{
"permissions": {
"allow": [
"Skill(sync_to_github)",
"Bash(python3:.claude/skills/sync_to_github/tools/*)",
"Bash(git:*)"
]
}
}Workflow Integration
工作流集成
Can be chained with other skills:
bash
undefined可与其他Skill链式调用:
bash
undefinedAfter note creation
创建笔记后
Skill(note-creator, "Create API docs")
Skill(sync_to_github, args="--push")
Skill(note-creator, "Create API docs")
Skill(sync_to_github, args="--push")
After code generation
代码生成后
... code changes ...
... 代码变更 ...
Skill(sync_to_github)
undefinedSkill(sync_to_github)
undefinedConfiguration
配置
Commit Message Customization
提交信息自定义
Edit to customize:
tools/git_sync.pypython
undefined编辑进行自定义:
tools/git_sync.pypython
undefinedDefault commit types
默认提交类型
COMMIT_TYPES = ["feat", "fix", "docs", "style", "refactor", "test", "chore", "perf"]
COMMIT_TYPES = ["feat", "fix", "docs", "style", "refactor", "test", "chore", "perf"]
Message template
信息模板
COMMIT_TEMPLATE = """{type}({scope}): {subject}
{body}
Co-Authored-By: Claude Sonnet noreply@anthropic.com
"""
undefinedCOMMIT_TEMPLATE = """{type}({scope}): {subject}
{body}
Co-Authored-By: Claude Sonnet noreply@anthropic.com
"""
undefinedBranch Behavior
分支行为
Default behavior:
- Commits to current branch
- Pushes to current branch's remote
- To change branch: before running skill
git checkout <branch>
默认行为:
- 提交至当前分支
- 推送至当前分支对应的远程仓库
- 如需切换分支:运行Skill前执行
git checkout <branch>
Best Practices
最佳实践
- Review before committing: Use to preview commit message
--dry-run - Stage selectively: Commit all changes or stage specific files first
- Meaningful changes: Ensure changes are complete before committing
- Branch management: Commit to feature branches, not main directly
- Commit frequency: Use for logical units of work, not every file save
- 提交前预览:使用预览提交信息
--dry-run - 选择性暂存:可提交所有变更或先暂存特定文件
- 有意义的变更:确保变更完成后再提交
- 分支管理:提交至功能分支,而非直接提交至主分支
- 提交频率:针对逻辑完整的工作单元提交,而非每次保存文件都提交
Limitations
局限性
- Requires at least one existing commit in repository
- Cannot handle merge conflicts
- Does not create pull requests
- Requires git configured with user.name and user.email
- Only commits to current branch
- 要求仓库中至少存在一条现有提交记录
- 无法处理合并冲突
- 不支持创建Pull Request
- 要求已配置Git的user.name和user.email
- 仅能提交至当前分支
Troubleshooting
故障排除
"git config" errors
"git config"错误
bash
git config --global user.name "Your Name"
git config --global user.email "your.email@example.com"bash
git config --global user.name "Your Name"
git config --global user.email "your.email@example.com"Large commits fail
大提交失败
- Consider splitting into smaller commits
- Check git LFS for large files
- 考虑拆分为更小的提交
- 检查是否使用Git LFS处理大文件
Push permission denied
推送权限被拒绝
- Check remote URL:
git remote -v - Verify authentication credentials
- Check branch permissions on GitHub
- 检查远程仓库URL:
git remote -v - 验证认证凭据
- 检查GitHub上的分支权限