AgentSkillsCN

Git

完整的Git版本控制工作流自动化。当用户提到提交、推送、拉取请求、PR、分支、合并、变基、暂存、git状态、暂存文件、未暂存更改或任何版本控制操作时使用。处理常规提交、安全检查和GitHub CLI集成。

SKILL.md
--- frontmatter
name: Git
description: Complete Git version control workflow automation. USE WHEN user mentions commit, push, pull request, PR, branch, merge, rebase, stash, git status, staged files, unstaged changes, OR any version control operations. Handles conventional commits, security checks, and GitHub CLI integration.

Git

Complete Git version control workflow automation for Claude Code. This skill provides safe, structured workflows for all common git operations with built-in security checks, conventional commit support, and GitHub CLI integration.

Workflow Routing

When executing a workflow, output this notification:

code
Running the **WorkflowName** workflow from the **Git** skill...
WorkflowTriggerFile
Commit"commit", "stage changes", "cm"workflows/Commit.md
CommitPush"commit and push", "push changes", "cp"workflows/CommitPush.md
PullRequest"create pr", "pull request", "open pr"workflows/PullRequest.md
Branch"create branch", "switch branch", "list branches"workflows/Branch.md
Merge"merge branch", "merge into"workflows/Merge.md
Rebase"rebase", "rebase onto"workflows/Rebase.md
Stash"stash changes", "save work", "pop stash"workflows/Stash.md
Status"git status", "what changed", "show changes"workflows/Status.md
Sync"sync branch", "pull latest", "update branch"workflows/Sync.md
Undo"undo commit", "reset", "revert"workflows/Undo.md
Log"git log", "commit history", "show commits"workflows/Log.md
Diff"show diff", "what changed", "compare"workflows/Diff.md
Worktree"worktree", "add worktree", "list worktrees", "remove worktree"workflows/Worktree.md

Examples

Example 1: Stage and commit changes locally

code
User: "Commit these changes"
→ Invokes Commit workflow
→ Reviews all modified files for sensitive data
→ Generates conventional commit message
→ Stages and commits changes (NO push)
→ Returns commit hash and summary

Example 2: Full commit and push workflow

code
User: "Push my changes"
→ Invokes CommitPush workflow
→ Security scan for credentials/secrets
→ Generates descriptive commit message
→ Commits and pushes to remote
→ Confirms successful push with branch info

Example 3: Create a pull request

code
User: "Create a PR to main"
→ Invokes PullRequest workflow
→ Summarizes all commits in branch
→ Generates PR title and description
→ Uses GitHub CLI to create PR
→ Returns PR URL and details

Example 4: Check repository status

code
User: "What's the git status?"
→ Invokes Status workflow
→ Shows staged/unstaged/untracked files
→ Displays current branch info
→ Shows ahead/behind remote status

Example 5: Create worktree for parallel development

code
User: "Create a worktree for the hotfix"
→ Invokes Worktree workflow
→ Creates new worktree directory
→ Checks out branch in isolated directory
→ Returns worktree path and branch info
→ Preserves current work context

Security Protocols

CRITICAL: The following are NEVER committed:

PatternExampleAction
Environment files.env, .env.local, .env.productionBlock commit
Credentialscredentials.json, *.pem, *.keyBlock commit
API keysHardcoded keys in sourceWarn and block
Database URLsConnection strings with passwordsBlock commit
Cloud configs*.tfvars, kubeconfigWarn user

Conventional Commits Reference

All commits follow Conventional Commits:

TypeWhen to Use
featNew feature or capability
fixBug fix
docsDocumentation only changes
styleFormatting, no code change
refactorCode restructuring, no behavior change
perfPerformance improvement
testAdding or fixing tests
buildBuild system or dependencies
ciCI/CD configuration
choreMaintenance tasks
revertReverting previous commits

Commit Message Format:

code
<type>(<scope>): <description>

[optional body]

[optional footer(s)]

Rules:

  • Title under 70 characters
  • Use imperative mood ("add" not "added")
  • No period at end of title
  • Body explains what and why, not how

Git Safety Rules

  1. NEVER force push to main/master without explicit user confirmation
  2. NEVER run destructive commands (git reset --hard, git clean -fd) without confirmation
  3. ALWAYS check for uncommitted changes before switching branches
  4. ALWAYS verify remote before pushing sensitive repos
  5. NEVER skip pre-commit hooks unless explicitly requested
  6. NEVER amend pushed commits without confirmation

AI Attribution Policy

DO NOT include AI attribution in commits:

  • No "Generated with [Claude Code]" signatures
  • No "Co-Authored-By: Claude" attributions
  • No AI tool references in commit messages
  • Create clean, professional commit messages

Tools

This skill uses standard git commands and optionally:

  • GitHub CLI (gh): For PR creation and GitHub operations
  • pre-commit: For validation hooks before commits

References

  • references/ConventionalCommits.md - Detailed conventional commits guide
  • references/GitBestPractices.md - Git workflow best practices
  • references/GitWorktree.md - Git worktree concepts and command reference
  • references/SecurityChecklist.md - Pre-commit security checklist