sync_to_github

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

sync_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:
  1. Analyzing current git status (staged and unstaged changes)
  2. Generating descriptive commit messages based on change content
  3. Creating commits with AI-generated messages
  4. Optionally pushing to remote repository
本Skill通过以下方式自动化Git工作流:
  1. 分析当前Git状态(已暂存和未暂存的变更)
  2. 根据变更内容生成描述性提交信息
  3. 使用AI生成的信息创建提交
  4. 可选推送至远程仓库

Input/Output Contract

输入/输出约定

Input

输入

  • No required parameters
  • Optional flags:
    • --push
      : Automatically push to remote after committing
    • --dry-run
      : Preview commit message without committing
  • 无必填参数
  • 可选标志:
    • --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
undefined
bash
undefined

Analyze 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")
undefined
Skill(sync_to_github, args="--dry-run")
undefined

Examples

示例

Example 1: Feature Development

示例1:功能开发

bash
undefined
bash
undefined

After 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
undefined
Skill(sync_to_github)

输出:
正在分析变更... 已修改文件: src/components/Button.tsx src/styles/button.css
生成的提交信息: feat: add Button component with hover states
  • 新增带有props接口的可复用Button组件
  • 实现悬停和激活状态动画
  • 添加用于按钮样式的CSS模块
已创建提交:abc123def
undefined

Example 2: Bug Fix

示例2:Bug修复

bash
undefined
bash
undefined

After 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
undefined
Skill(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
undefined

Example 3: Documentation Update

示例3:文档更新

bash
undefined
bash
undefined

After 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
undefined
Skill(sync_to_github)

输出:
正在分析变更... 已修改文件: README.md docs/api.md docs/examples.md
生成的提交信息: docs: update API documentation with new endpoints
  • 添加新的认证端点示例
  • 明确速率限制规则
  • 修复API参考中的失效链接
已创建提交:def123ghi
undefined

Implementation

实现细节

The skill uses the Python tool at
tools/git_sync.py
which:
  1. Analyzes git status
    bash
    git status --porcelain
    git diff --cached
    git diff
  2. 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
  3. Creates commit
    bash
    git add .
    git commit -m "<generated message>"
  4. Optional push
    bash
    git push
本Skill使用位于
tools/git_sync.py
的Python工具,具体流程如下:
  1. 分析Git状态
    bash
    git status --porcelain
    git diff --cached
    git diff
  2. 生成提交信息
    • 分类变更类型(feat/fix/docs/refactor/test/chore等)
    • 在标题中总结主要变更
    • 用项目符号列出具体变更内容
    • 遵循规范化提交格式
  3. 创建提交
    bash
    git add .
    git commit -m "<generated message>"
  4. 可选推送
    bash
    git push

Commit Message Format

提交信息格式

Follows conventional commits specification:
<type>(<scope>): <subject>

<body>

<footer>
Types:
  • feat
    : New feature
  • fix
    : Bug fix
  • docs
    : Documentation changes
  • style
    : Code style changes (formatting)
  • refactor
    : Code refactoring
  • test
    : Adding or updating tests
  • chore
    : Maintenance tasks
  • perf
    : Performance improvements
遵循规范化提交规范:
<type>(<scope>): <subject>

<body>

<footer>
类型说明:
  • feat
    :新功能
  • fix
    :Bug修复
  • 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 init

Nothing 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 push

Integration

集成

Permissions

权限配置

Add to
.claude/settings.local.json
:
json
{
  "permissions": {
    "allow": [
      "Skill(sync_to_github)",
      "Bash(python3:.claude/skills/sync_to_github/tools/*)",
      "Bash(git:*)"
    ]
  }
}
添加至
.claude/settings.local.json
json
{
  "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
undefined

After 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)
undefined
Skill(sync_to_github)
undefined

Configuration

配置

Commit Message Customization

提交信息自定义

Edit
tools/git_sync.py
to customize:
python
undefined
编辑
tools/git_sync.py
进行自定义:
python
undefined

Default 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 """
undefined
COMMIT_TEMPLATE = """{type}({scope}): {subject}
{body}
Co-Authored-By: Claude Sonnet noreply@anthropic.com """
undefined

Branch Behavior

分支行为

Default behavior:
  • Commits to current branch
  • Pushes to current branch's remote
  • To change branch:
    git checkout <branch>
    before running skill
默认行为:
  • 提交至当前分支
  • 推送至当前分支对应的远程仓库
  • 如需切换分支:运行Skill前执行
    git checkout <branch>

Best Practices

最佳实践

  1. Review before committing: Use
    --dry-run
    to preview commit message
  2. Stage selectively: Commit all changes or stage specific files first
  3. Meaningful changes: Ensure changes are complete before committing
  4. Branch management: Commit to feature branches, not main directly
  5. Commit frequency: Use for logical units of work, not every file save
  1. 提交前预览:使用
    --dry-run
    预览提交信息
  2. 选择性暂存:可提交所有变更或先暂存特定文件
  3. 有意义的变更:确保变更完成后再提交
  4. 分支管理:提交至功能分支,而非直接提交至主分支
  5. 提交频率:针对逻辑完整的工作单元提交,而非每次保存文件都提交

Limitations

局限性

  1. Requires at least one existing commit in repository
  2. Cannot handle merge conflicts
  3. Does not create pull requests
  4. Requires git configured with user.name and user.email
  5. Only commits to current branch
  1. 要求仓库中至少存在一条现有提交记录
  2. 无法处理合并冲突
  3. 不支持创建Pull Request
  4. 要求已配置Git的user.name和user.email
  5. 仅能提交至当前分支

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上的分支权限