---
name: git-workflow
version: "2.0.0"
category: tools
description: "当用户需要 git 工作流指导时使用：分支管理、cherry-pick、rebase、stash、冲突解决。使用 config/git.yaml 进行仓库设置。Use when user needs git workflow guidance: branch management, cherry-pick, rebase, stash, or conflict resolution. Uses config/git.yaml for repository settings."
triggers:
  zh: ["git", "commit", "push", "merge", "rebase", "branch", "stash", "PR", "提交", "推送", "合并", "分支"]
  en: ["git", "commit", "push", "merge", "rebase", "branch", "PR"]
license: MIT
compatibility: Node.js >= 14
config: 
  - config/git.yaml
  - config/credentials.yaml
dependencies: 
  - None
metadata: 
author: "sunhongda20204834@example.com"
created: "2025-06-16"
updated: "2026-06-16"
status: "stable"
---

# Git工作流 / Git Workflow

## Changelog / 版本履历
<!-- Track all changes to this skill. Update this table whenever you modify the skill. -->
| 日期 | 版本 | 变更摘要 |
|------|------|---------|
| 2025-06-16 | 2.0.0 | 重构：增加配置驱动、安全规则、自动推送验证、凭证管理 |
| 2026-06-16 | 2.0.0 | 规范化调整 |

***
## Core Concept / 核心概念

### 🇨🇳
一句话说清：输入什么 → 做什么 → 输出什么。明确 **不做什么**。

**输入**: git workflow request | **输出**: operation result with safety checks | **不负责**: actual git command execution (handled by git-safe)

### 🇺🇸
One line: Input → Process → Output. Explicitly state what is **NOT done**.

**Input**: git workflow request | **Output**: operation result with safety checks | **NOT responsible for**: actual git command execution (handled by git-safe)

***
## Position / 定位

```
tools router → git-workflow → config/credentials
    (input source)        (output flow)
```

***
## Description / 描述
<!-- One paragraph describing what this skill does, when to use it, and what makes it unique. Keep it concise and bilingual. -->
Git workflow assistant automates common git operations including branch management, conflict resolution, cherry-pick, rebase, and stash. It reads repository configuration from config/git.yaml (remote URLs, branches, user info) and credentials from config/credentials.yaml. The skill never auto-executes destructive commands like force push or hard reset, always performs pre-operation workspace checks, and validates results post-execution. / Git 工作流助手自动化常见的 git 操作，包括分支管理、冲突解决、cherry-pick、rebase 和 stash。它从 config/git.yaml（远程 URL、分支、用户信息）读取仓库配置，从 config/credentials.yaml 读取凭证。该技能绝不自动执行破坏性命令（如强制推送或硬重置），始终执行操作前工作区检查，并在执行后验证结果。

## Triggers / 触发词
<!-- List keywords that should trigger this skill. These are used by routing systems like 'easy' to auto-select skills. -->
- English: 'git', 'commit', 'push', 'merge', 'rebase', 'branch', 'PR'
- 中文: 'git', '提交', '推送', '合并', '分支'

## Capabilities / 能力
<!-- List specific capabilities this skill provides. Each item should be a concrete ability with brief explanation. -->
- Automated branch management - Create, switch, delete, and list branches with safety checks
- Conflict resolution guidance - Identify and guide manual resolution of merge conflicts
- Cherry-pick operations - Selectively apply commits from other branches
- Rebase with validation - Perform rebasing with pre-checks and user confirmation for risks
- Stash management - Save and restore work-in-progress changes safely
- Configuration-driven operations - Use config files for repository-specific settings

## Dependencies / 依赖
<!-- List other skills, config files, or resources this skill depends on. Explain why each dependency is needed. -->
- config/git.yaml - Repository configuration including remote URLs, default branches, and user info
- config/credentials.yaml - Authentication tokens for remote operations
- None - No other skill dependencies required

## Usage / 使用方式

### Invocation / 调用方式
<!-- Explain how this skill is typically invoked - via easy auto-routing, auto orchestration, expert direct call, or domain router. -->
This skill is typically invoked via the tools domain router when git workflow keywords are detected. It can also be called directly using the expert entry point for specific operations.

### Parameters / 参数
<!-- Document all parameters this skill accepts. Use the table format below. -->
| 参数 | 类型 | 必填 | 说明 |
|------|------|------|------|
| operation | string | ✅ | Specific git operation (branch, merge, cherry-pick, rebase, stash) |
| options | object | ❌ | Operation-specific options and parameters |

### Example / 示例
<!-- Show concrete examples of how to invoke this skill. Use code blocks for commands. -->
```
/tools git branch create feature-login
/tools git merge develop --no-ff
/tools git cherry-pick abc123def
```

## Output Format / 输出格式
<!-- Describe what this skill produces - JSON, Markdown report, code files, etc. Be specific about structure and content. -->
The skill produces structured output showing operation status, affected files, and any warnings or errors. For complex operations like merges with conflicts, it provides detailed conflict location information and resolution guidance.

## Configuration / 配置
<!-- If this skill reads any YAML config files, document them here with their structure and purpose. -->
- config/git.yaml: Contains repository remote URLs, default branches, user information, and security rules
- config/credentials.yaml: Contains authentication tokens for Gitee/GitHub access, injected as environment variables

***
## Iron Law / 核心铁律

### 🇨🇳
1. **铁律1**: 始终先加载 config/git.yaml 配置文件。违规示例：❌ 跳过配置直接执行操作。合规示例：✅ 验证配置完整性后再继续。
2. **铁律2**: 在执行任何操作前必须验证工作区状态。违规示例：❌ 在未检查工作区的情况下执行 rebase。合规示例：✅ 运行 git status 确认无未提交更改。
3. **铁律3**: 绝不自动解决冲突，破坏性操作必须要求用户确认。违规示例：❌ 自动 resolve merge conflicts 或 force push 无需确认。合规示例：✅ 明确标识冲突并等待用户手动解决，强制操作前要求明确授权。

### 🇺🇸
1. **Law 1**: Always load config/git.yaml first. Violation: ❌ Skip configuration and execute operations directly. Compliance: ✅ Validate configuration completeness before proceeding.
2. **Law 2**: Verify workspace state before any operations. Violation: ❌ Execute rebase without checking workspace. Compliance: ✅ Run git status to confirm no uncommitted changes.
3. **Law 3**: Never auto-resolve conflicts; destructive operations always require user confirmation. Violation: ❌ Auto-resolve merge conflicts or force push without confirmation. Compliance: ✅ Clearly identify conflicts and wait for manual resolution; require explicit authorization for force operations.

***
## Rationalization Table / 合理化防御表
<!-- REQUIRED for quality/workflow/tools domains. Prevents model rationalization. -->

| # | Trap / 陷阱 | Question / 请问自己 | Action / 应该怎么做 |
|---|-------------|------------------|------------------|
| 1 | "I can just merge without checking the workspace" | Have I verified the current git status and recent log? | Always run pre-operation workspace checks before any git workflow operation |
| 2 | "The conflict is simple, I'll auto-resolve" | Does the Iron Law allow automatic conflict resolution? | Never auto-resolve conflicts; always require manual user intervention for conflict resolution |
| 3 | "Force push is safe in this case" | Have I obtained explicit user confirmation for this destructive operation? | Always require explicit user confirmation before executing any destructive operations like force push |

***
## Red Flags / 三层防御

### Layer 1: Input / 输入
- **INPUT-01**: config/git.yaml missing → 🔴 CRITICAL → Abort operation and request configuration
- **INPUT-02**: workspace has uncommitted changes → 🟡 WARN → Alert user and require confirmation to proceed

### Layer 2: Execution / 执行
- **EXEC-01**: uncommitted changes detected before rebase → 🔴 CRITICAL → Halt operation and instruct user to commit or stash changes
- **EXEC-02**: force push attempted without explicit confirmation → 🔴 CRITICAL → Require explicit user authorization before proceeding

### Layer 3: Output / 输出
- **OUTPUT-01**: conflicts not properly documented in output → 🔴 CRITICAL → Ensure all conflicts are clearly identified with file paths and resolution guidance
- **OUTPUT-02**: credentials exposed in output logs → 🔴 CRITICAL → Scrub all credential-related information from output

**级别标识**: 🔴 CRITICAL → 中断 | 🟡 WARN → 继续+标记 | 🔵 INFO → 记录

***
## Workflow / 工作流程
<!-- Detail the step-by-step workflow this skill follows. Number each step clearly. -->
1. Load configuration - Read config/git.yaml and config/credentials.yaml, validate completeness
2. Check workspace state - Run git status and recent log to assess current repository state
3. Execute operation - Perform the requested git operation with appropriate safety checks
4. Verify results - Confirm operation success and provide structured output with any necessary next steps

## Auto-Review / 自检清单
<!-- Checklist that should be automatically verified after skill execution. This helps ensure quality and completeness. -->
| # | 检查项 |
|---|--------|
| 1 | Required config files were properly loaded |
| 2 | Workspace status was checked before operations |
| 3 | Destructive operations required explicit user confirmation |
| 4 | Credentials were handled securely (not displayed in output) |
| 5 | Operation results were properly validated and reported |
| 6 | Conflicts were identified but not automatically resolved |
