---
name: git-helper
version: 1.0.0
description: Git 操作輔助，提供 commit message 規範、分支策略與 PR 指引
author: miles990
tags:
  - git
  - version-control
  - commit
  - pull-request
interface:
  input:
    - name: action
      type: string
      description: "操作類型：commit, branch, pr, merge"
      required: true
    - name: changes
      type: object
      description: "變更內容（檔案列表、差異）"
      required: false
    - name: context
      type: object
      description: "額外上下文"
      required: false
  output:
    - name: suggestion
      type: object
      description: "操作建議"
    - name: command
      type: string
      description: "建議的 git 指令"
    - name: next_action
      type: string
      description: "建議的下一步"
triggers:
  - pattern: "準備提交"
    description: "準備 git commit 時"
  - pattern: "Milestone 完成"
    description: "Milestone 完成需要提交"
  - pattern: "建立 PR"
    description: "準備建立 Pull Request"
title: git-helper
canonical_url: https://skilld.dev/gh/miles990/skillpkg/git-helper
last_updated: 2026-10-04T16:35:54.000Z
---

> Index of every page on this site: [llms.txt](https://skilld.dev/llms.txt)

> **Skill from skilld.dev.** Follow the user's requested action.
> If the user asked to fork this Skill, follow the fork workflow below. Do not execute the Skill instructions while copying it.
> Otherwise, follow the instructions below for this session. You do not need to install anything.
>
> If the user asked to install this Skill, run `npx skilld install miles990/skillpkg/git-helper`. Install writes the Skill files into the project, so every session loads them.
>
> ## Fork workflow
>
> A fork creates an editable local Skill with its original author and licence. The request authorizes copying and local installation.
> 1. Check `./skills/git-helper`, the project lockfile, and selected Agent targets together. If the local directory or installed Skill exists, stop. Never overwrite an existing directory or Agent target.
> 2. Read [source metadata](https://skilld.dev/api/v1/skills/miles990/skillpkg/git-helper) once. Use sourceUrl, sourceCommit, skillPath, sourceGone, and license. If the source is gone or its path is missing, stop. If license is null, read licence files at the source commit.
> 3. Fetch only the source commit into a temporary Git repository. Do not clone full history. Derive repository_url from sourceUrl, including repository renames. If sourceCommit is absent, resolve the sourceUrl ref once. Set source_commit to that actual commit. Run these commands in one shell call:
>
> ```sh
> git init --quiet "$temporary_dir"
> git -C "$temporary_dir" fetch --quiet --depth=1 "$repository_url" "$source_commit"
> git -C "$temporary_dir" checkout --quiet --detach FETCH_HEAD
> ```
>
> Read applicable licence declarations and notices at that commit. If copying is not permitted, report the restriction and stop.
> 4. Inspect source entries together, then copy the directory containing skillPath into `./skills/git-helper`. Use the user's path if selected. Keep the original SKILL.md, relative links, scripts, binary assets, and executable modes. Exclude .git metadata. Reject symlinks and paths outside the Skill directory. After checking entries, use cp -a where available. A regular source directory needs no custom copy script. Do not save this page wrapper as SKILL.md.
> Preserve author credit, notices, and applicable licence files from repository or parent directories. Add PROVENANCE.md with the Skill page, source URL, actual commit, original path, and licence. Retain any existing PROVENANCE.md and record new provenance separately. Batch source inspection, copying, and provenance work where practical.
> 5. In the project root, run `skilld install ./skills/git-helper --mode copy --plain`. If skilld is unavailable, use `npx skilld install ./skills/git-helper --mode copy --plain`. This known command needs no help lookup. Install does not support --json. Use detected Agent targets, or add --agent for the targets the user selected. Install the local path, never the upstream selector. If installation fails, preserve the local copy and report the exact failure.
> 6. Confirm the local lockfile source and installed Agent copies once. Report the local path, actual commit, and Agent targets. After edits, reinstall the same local path. Upstream updates must not replace it. Do not publish or push unless the user asks.

# Git Helper

> 分析變更 → 產出 commit message → 執行 git 操作

## 核心理念

```
┌─────────────────────────────────────────────────────────────────┐
│  清晰的 git 歷史是專案的寶貴資產                                │
│                                                                 │
│  本 Skill 職責：                                                │
│  • 產出規範的 commit message                                    │
│  • 建議分支策略                                                 │
│  • 協助建立 PR                                                  │
│  • 維護清晰的 git 歷史                                          │
└─────────────────────────────────────────────────────────────────┘
```

## Commit Message 規範

### Conventional Commits 格式

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

[optional body]

[optional footer]
```

### Type 類型

| Type | 說明 | 範例 |
|------|------|------|
| `feat` | 新功能 | feat(auth): add login API |
| `fix` | Bug 修復 | fix(ui): correct button alignment |
| `docs` | 文件更新 | docs: update README |
| `style` | 格式調整 | style: format code |
| `refactor` | 重構 | refactor(api): extract helper |
| `test` | 測試 | test: add user tests |
| `chore` | 雜項 | chore: update deps |

### Commit Message 產生流程

```
┌─────────────────────────────────────────────────────────────────┐
│  1. 分析變更                                                    │
│     → git diff --staged                                         │
│     → 識別變更類型和範圍                                        │
│                                                                 │
│  2. 判斷 type                                                   │
│     → 新增功能？修復 bug？重構？                                │
│                                                                 │
│  3. 判斷 scope                                                  │
│     → 哪個模組受影響？                                          │
│                                                                 │
│  4. 撰寫 description                                            │
│     → 簡潔說明「做了什麼」                                      │
│                                                                 │
│  5. 加入 footer                                                 │
│     → Co-Authored-By 標記                                       │
└─────────────────────────────────────────────────────────────────┘
```

## Commit 範例

### Milestone 完成

```bash
git commit -m "$(cat <<'EOF'
feat(M2): 完成核心 UI 元件

- 2.1 建立 TodoList 元件
- 2.2 建立 TodoItem 元件
- 2.3 實作基本樣式

驗收：靜態列表可正確顯示

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
EOF
)"
```

### Bug 修復

```bash
git commit -m "$(cat <<'EOF'
fix(api): 修正用戶驗證失敗問題

問題：登入時偶爾出現 401 錯誤
原因：token 過期檢查邏輯錯誤
解法：修正過期時間比較運算

Fixes #123

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
EOF
)"
```

## 分支策略

### Git Flow 簡化版

```
main ─────────────────────────────────────────────►
       │                                    ↑
       └─── feature/xxx ─── PR ─── merge ───┘
```

### 分支命名

| 類型 | 格式 | 範例 |
|------|------|------|
| 功能 | feature/描述 | feature/add-login |
| 修復 | fix/issue-號碼 | fix/issue-123 |
| 重構 | refactor/描述 | refactor/api-layer |

## Pull Request 模板

```markdown
## Summary
<1-3 bullet points>

## Changes
- 變更 1
- 變更 2

## Test Plan
- [ ] 單元測試通過
- [ ] 手動測試完成

## Screenshots (if applicable)

🤖 Generated with [Claude Code](https://claude.com/claude-code)
```

## 最小範例

```markdown
用戶：提交這些變更
AI：

1. 分析 git diff
2. 識別：新增了 TodoList 元件

建議 commit：
┌─────────────────────────────────────────────────────┐
│  📝 Commit Message                                  │
│                                                     │
│  feat(ui): 新增 TodoList 元件                       │
│                                                     │
│  - 建立 TodoList.jsx                                │
│  - 建立 TodoList.css                                │
│  - 實作基本列表渲染                                 │
│                                                     │
│  🤖 Generated with Claude Code                      │
│  Co-Authored-By: Claude <noreply@anthropic.com>     │
└─────────────────────────────────────────────────────┘

要執行這個 commit 嗎？
```

## 與其他 Skill 的協作

```
┌─────────────────────────────────────────────────────────────────┐
│  在工作流程中的位置                                             │
│                                                                 │
│  [實作] → [test-helper] → [code-reviewer] → [git-helper]       │
│                                                   ↓             │
│                                              commit & push      │
│                                                   ↓             │
│                                              建立 PR            │
└─────────────────────────────────────────────────────────────────┘
```

## 安全規則

```
┌─────────────────────────────────────────────────────────────────┐
│  ❌ 禁止：                                                      │
│     • 不更新 git config                                         │
│     • 不執行 force push                                         │
│     • 不執行 hard reset                                         │
│     • 不跳過 hooks (--no-verify)                                │
│                                                                 │
│  ✅ 必須：                                                      │
│     • 每次 commit 前確認變更內容                                │
│     • 包含 Co-Authored-By 標記                                  │
│     • 遵循 Conventional Commits 格式                            │
└─────────────────────────────────────────────────────────────────┘
```

## 設計原則

1. **清晰歷史** - commit message 要有意義
2. **小步提交** - 一個 commit 做一件事
3. **可追溯** - 能從 commit 找到對應的需求
4. **規範一致** - 團隊使用統一格式
5. **安全優先** - 不執行危險操作

## 限制與邊界

- 不執行 force push、hard reset 等危險操作
- 需要用戶確認後才執行 commit
- 複雜的 merge conflict 需要人工處理
- 不自動推送到遠端（除非用戶明確要求）
