git-workflow-and-versioning
コード変更時に、コミットやブランチ作成、コンフリクト解消、複数並行作業の整理など、Gitを使ったバージョン管理とワークフローを適切に運用し、チーム開発を円滑に進めるSkill。
📜 元の英語説明(参考)
Use when making any code change. Use when committing, branching, resolving conflicts, or when you need to organize work across multiple parallel streams.
🇯🇵 日本人クリエイター向け解説
コード変更時に、コミットやブランチ作成、コンフリクト解消、複数並行作業の整理など、Gitを使ったバージョン管理とワークフローを適切に運用し、チーム開発を円滑に進めるSkill。
※ jpskill.com 編集部が日本のビジネス現場向けに補足した解説です。Skill本体の挙動とは独立した参考情報です。
下記のコマンドをコピーしてターミナル(Mac/Linux)または PowerShell(Windows)に貼り付けてください。 ダウンロード → 解凍 → 配置まで全自動。
mkdir -p ~/.claude/skills && cd ~/.claude/skills && curl -L -o git-workflow-and-versioning.zip https://jpskill.com/download/9582.zip && unzip -o git-workflow-and-versioning.zip && rm git-workflow-and-versioning.zip
$d = "$env:USERPROFILE\.claude\skills"; ni -Force -ItemType Directory $d | Out-Null; iwr https://jpskill.com/download/9582.zip -OutFile "$d\git-workflow-and-versioning.zip"; Expand-Archive "$d\git-workflow-and-versioning.zip" -DestinationPath $d -Force; ri "$d\git-workflow-and-versioning.zip"
完了後、Claude Code を再起動 → 普通に「動画プロンプト作って」のように話しかけるだけで自動発動します。
💾 手動でダウンロードしたい(コマンドが難しい人向け)
- 1. 下の青いボタンを押して
git-workflow-and-versioning.zipをダウンロード - 2. ZIPファイルをダブルクリックで解凍 →
git-workflow-and-versioningフォルダができる - 3. そのフォルダを
C:\Users\あなたの名前\.claude\skills\(Win)または~/.claude/skills/(Mac)へ移動 - 4. Claude Code を再起動
⚠️ ダウンロード・利用は自己責任でお願いします。当サイトは内容・動作・安全性について責任を負いません。
🎯 このSkillでできること
下記の説明文を読むと、このSkillがあなたに何をしてくれるかが分かります。Claudeにこの分野の依頼をすると、自動で発動します。
📦 インストール方法 (3ステップ)
- 1. 上の「ダウンロード」ボタンを押して .skill ファイルを取得
- 2. ファイル名の拡張子を .skill から .zip に変えて展開(macは自動展開可)
- 3. 展開してできたフォルダを、ホームフォルダの
.claude/skills/に置く- · macOS / Linux:
~/.claude/skills/ - · Windows:
%USERPROFILE%\.claude\skills\
- · macOS / Linux:
Claude Code を再起動すれば完了。「このSkillを使って…」と話しかけなくても、関連する依頼で自動的に呼び出されます。
詳しい使い方ガイドを見る →- 最終更新
- 2026-05-18
- 取得日時
- 2026-05-18
- 同梱ファイル
- 1
📖 Skill本文(日本語訳)
※ 原文(英語/中国語)を Gemini で日本語化したものです。Claude 自身は原文を読みます。誤訳がある場合は原文をご確認ください。
Git ワークフローとバージョン管理
概要
Git はあなたの安全網です。コミットをセーブポイント、ブランチをサンドボックス、履歴をドキュメントとして扱いましょう。AI エージェントが高速でコードを生成する時代において、規律あるバージョン管理は、変更を管理しやすく、レビュー可能で、元に戻せるようにするためのメカニズムです。
どのような時に使うか
常にです。すべてのコード変更は git を通ります。
コア原則
1. 早めに、頻繁にコミットする
成功したインクリメントごとに、独自のコミットを作成します。コミットされていない大きな変更を蓄積しないでください。
ワークパターン:
スライスを実装 → テスト → 検証 → コミット → 次のスライス
これではない:
すべてを実装 → 動作することを期待 → 巨大なコミット
コミットはセーブポイントです。次の変更で何かが壊れた場合、最後に既知の正常な状態に即座に戻すことができます。
2. アトミックコミット
各コミットは、1つの論理的なことを行います。
# 良い例: 各コミットは自己完結している
git log --oneline
a1b2c3d バリデーション付きのタスク作成エンドポイントを追加
d4e5f6g タスク作成フォームコンポーネントを追加
h7i8j9k フォームを API に接続し、ローディング状態を追加
m1n2o3p タスク作成テストを追加 (ユニット + 統合)
# 悪い例: すべてが混ざっている
git log --oneline
x1y2z3a タスク機能を追加、サイドバーを修正、依存関係を更新、ユーティリティをリファクタリング
3. 説明的なメッセージ
コミットメッセージは、何を したかだけでなく、なぜ したかを説明します。
# 良い例: 意図を説明している
feat: 登録エンドポイントにメール検証を追加
無効なメール形式がデータベースに到達するのを防ぎます。
auth.ts の既存の検証パターンと一貫性を持たせるため、
ルートハンドラーレベルで Zod スキーマ検証を使用します。
# 悪い例: diff から明らかなことを記述している
update auth.ts
形式:
<type>: <短い説明>
<オプションの本文: なぜそうしたのかを説明 (何をしたかではない)>
種類:
feat— 新機能fix— バグ修正refactor— バグを修正したり、機能を追加したりしないコード変更test— テストの追加または更新docs— ドキュメントのみchore— ツール、依存関係、設定
4. 関心を混ぜない
フォーマットの変更と動作の変更を組み合わせないでください。リファクタリングと機能を組み合わせないでください。各種類の変更は、個別のコミットにする必要があります。
# 良い例: 関心を分離
git commit -m "refactor: 検証ロジックを共有ユーティリティに抽出"
git commit -m "feat: 登録に電話番号の検証を追加"
# 悪い例: 関心が混ざっている
git commit -m "検証をリファクタリングし、電話番号フィールドを追加"
ブランチ戦略
フィーチャーブランチ
main (常にデプロイ可能)
│
├── feature/task-creation ← ブランチごとに1つの機能
├── feature/user-settings ← 並行作業
└── fix/duplicate-tasks ← バグ修正
main(またはチームのデフォルトブランチ) からブランチを作成します- ブランチを短命に保ちます (1〜3日以内にマージ)
- マージ後にブランチを削除します
ブランチの命名
feature/<短い説明> → feature/task-creation
fix/<短い説明> → fix/duplicate-tasks
chore/<短い説明> → chore/update-deps
refactor/<短い説明> → refactor/auth-module
ワークツリーの操作
並行した AI エージェントの作業には、git ワークツリーを使用して、複数のブランチを同時に実行します。
# フィーチャーブランチのワークツリーを作成
git worktree add ../project-feature-a feature/task-creation
git worktree add ../project-feature-b feature/user-settings
# 各ワークツリーは、独自のブランチを持つ個別のディレクトリです
# エージェントは干渉することなく並行して作業できます
ls ../
project/ ← main ブランチ
project-feature-a/ ← task-creation ブランチ
project-feature-b/ ← user-settings ブランチ
# 完了したら、マージしてクリーンアップ
git worktree remove ../project-feature-a
利点:
- 複数のエージェントが異なる機能を同時に操作できます
- ブランチの切り替えは不要です (各ディレクトリに独自のブランチがあります)
- 1つの実験が失敗した場合、ワークツリーを削除します — 何も失われません
- 変更は明示的にマージされるまで隔離されます
セーブポイントパターン
エージェントが作業を開始
│
├── 変更を加える
│ ├── テストに合格? → コミット → 続行
│ └── テストに失敗? → 最後のコミットに戻す → 調査
│
├── 別の変更を加える
│ ├── テストに合格? → コミット → 続行
│ └── テストに失敗? → 最後のコミットに戻す → 調査
│
└── 機能が完了 → すべてのコミットがクリーンな履歴を形成
このパターンは、作業のインクリメントを1つ以上失うことがないことを意味します。エージェントが暴走した場合、git reset --hard HEAD を実行すると、最後に成功した状態に戻ります。
変更の概要
変更を加えた後は、構造化された概要を提供します。これにより、レビューが容易になり、スコープの規律が文書化され、意図しない変更が表面化します。
変更点:
- src/routes/tasks.ts: POST エンドポイントに検証ミドルウェアを追加
- src/lib/validation.ts: Zod を使用して TaskCreateSchema を追加
意図的に触れなかったもの:
- src/routes/auth.ts: 同様の検証ギャップがありますが、スコープ外です
- src/middleware/error.ts: エラー形式を改善できます (別のタスク)
潜在的な懸念事項:
- Zod スキーマは厳密で、余分なフィールドを拒否します。これが望ましいことを確認してください。
- zod を依存関係として追加しました (72KB gzip 圧縮) — すでに package.json にあります
このパターンは、間違った仮定を早期に把握し、レビュー担当者に変更の明確なマップを提供します。「触れなかったもの」セクションは特に重要です。これは、スコープの規律を守り、不要な改修を行わなかったことを示しています。
コミット前の衛生管理
コミットする前に:
# 1. コミットしようとしているものを確認
git diff --staged
# 2. シークレットがないことを確認
git diff --staged | grep -i "password\|secret\|api_key\|token"
# 3. テストを実行
npm test
# 4. リンティングを実行
npm run lint
# 5. 型チェックを実行
npx tsc --noEmit
git hooks でこれを自動化します。
// package.json (lint-staged + husky を使用)
{
"lint-staged": {
"*.{ts,tsx}": ["eslint --fix", "prettier --write"],
"*.{json,md}": ["prettier --write"]
}
}
生成されたファイルの処理
- プロジェクトが生成されたファイルを想定している場合にのみ、生成されたファイルをコミットします (例:
package-lock.json、Prisma マイグレーション) - ビルド出力 (
dist/、.next/)、環境変数はコミットしないでください
(原文はここで切り詰められています)
📜 原文 SKILL.md(Claudeが読む英語/中国語)を展開
Git Workflow and Versioning
Overview
Git is your safety net. Treat commits as save points, branches as sandboxes, and history as documentation. With AI agents generating code at high speed, disciplined version control is the mechanism that keeps changes manageable, reviewable, and reversible.
When to Use
Always. Every code change flows through git.
Core Principles
1. Commit Early, Commit Often
Each successful increment gets its own commit. Don't accumulate large uncommitted changes.
Work pattern:
Implement slice → Test → Verify → Commit → Next slice
Not this:
Implement everything → Hope it works → Giant commit
Commits are save points. If the next change breaks something, you can revert to the last known-good state instantly.
2. Atomic Commits
Each commit does one logical thing:
# Good: Each commit is self-contained
git log --oneline
a1b2c3d Add task creation endpoint with validation
d4e5f6g Add task creation form component
h7i8j9k Connect form to API and add loading state
m1n2o3p Add task creation tests (unit + integration)
# Bad: Everything mixed together
git log --oneline
x1y2z3a Add task feature, fix sidebar, update deps, refactor utils
3. Descriptive Messages
Commit messages explain the why, not just the what:
# Good: Explains intent
feat: add email validation to registration endpoint
Prevents invalid email formats from reaching the database.
Uses Zod schema validation at the route handler level,
consistent with existing validation patterns in auth.ts.
# Bad: Describes what's obvious from the diff
update auth.ts
Format:
<type>: <short description>
<optional body explaining why, not what>
Types:
feat— New featurefix— Bug fixrefactor— Code change that neither fixes a bug nor adds a featuretest— Adding or updating testsdocs— Documentation onlychore— Tooling, dependencies, config
4. Never Mix Concerns
Don't combine formatting changes with behavior changes. Don't combine refactors with features. Each type of change should be a separate commit:
# Good: Separate concerns
git commit -m "refactor: extract validation logic to shared utility"
git commit -m "feat: add phone number validation to registration"
# Bad: Mixed concerns
git commit -m "refactor validation and add phone number field"
Branching Strategy
Feature Branches
main (always deployable)
│
├── feature/task-creation ← One feature per branch
├── feature/user-settings ← Parallel work
└── fix/duplicate-tasks ← Bug fixes
- Branch from
main(or the team's default branch) - Keep branches short-lived (merge within 1-3 days)
- Delete branches after merge
Branch Naming
feature/<short-description> → feature/task-creation
fix/<short-description> → fix/duplicate-tasks
chore/<short-description> → chore/update-deps
refactor/<short-description> → refactor/auth-module
Working with Worktrees
For parallel AI agent work, use git worktrees to run multiple branches simultaneously:
# Create a worktree for a feature branch
git worktree add ../project-feature-a feature/task-creation
git worktree add ../project-feature-b feature/user-settings
# Each worktree is a separate directory with its own branch
# Agents can work in parallel without interfering
ls ../
project/ ← main branch
project-feature-a/ ← task-creation branch
project-feature-b/ ← user-settings branch
# When done, merge and clean up
git worktree remove ../project-feature-a
Benefits:
- Multiple agents can work on different features simultaneously
- No branch switching needed (each directory has its own branch)
- If one experiment fails, delete the worktree — nothing is lost
- Changes are isolated until explicitly merged
The Save Point Pattern
Agent starts work
│
├── Makes a change
│ ├── Test passes? → Commit → Continue
│ └── Test fails? → Revert to last commit → Investigate
│
├── Makes another change
│ ├── Test passes? → Commit → Continue
│ └── Test fails? → Revert to last commit → Investigate
│
└── Feature complete → All commits form a clean history
This pattern means you never lose more than one increment of work. If an agent goes off the rails, git reset --hard HEAD takes you back to the last successful state.
Change Summaries
After any modification, provide a structured summary. This makes review easier, documents scope discipline, and surfaces unintended changes:
CHANGES MADE:
- src/routes/tasks.ts: Added validation middleware to POST endpoint
- src/lib/validation.ts: Added TaskCreateSchema using Zod
THINGS I DIDN'T TOUCH (intentionally):
- src/routes/auth.ts: Has similar validation gap but out of scope
- src/middleware/error.ts: Error format could be improved (separate task)
POTENTIAL CONCERNS:
- The Zod schema is strict — rejects extra fields. Confirm this is desired.
- Added zod as a dependency (72KB gzipped) — already in package.json
This pattern catches wrong assumptions early and gives reviewers a clear map of the change. The "DIDN'T TOUCH" section is especially important — it shows you exercised scope discipline and didn't go on an unsolicited renovation.
Pre-Commit Hygiene
Before every commit:
# 1. Check what you're about to commit
git diff --staged
# 2. Ensure no secrets
git diff --staged | grep -i "password\|secret\|api_key\|token"
# 3. Run tests
npm test
# 4. Run linting
npm run lint
# 5. Run type checking
npx tsc --noEmit
Automate this with git hooks:
// package.json (using lint-staged + husky)
{
"lint-staged": {
"*.{ts,tsx}": ["eslint --fix", "prettier --write"],
"*.{json,md}": ["prettier --write"]
}
}
Handling Generated Files
- Commit generated files only if the project expects them (e.g.,
package-lock.json, Prisma migrations) - Don't commit build output (
dist/,.next/), environment files (.env), or IDE config (.vscode/settings.jsonunless shared) - Always have a
.gitignorethat covers:node_modules/,dist/,.env,.env.local,*.pem
Using Git for Debugging
# Find which commit introduced a bug
git bisect start
git bisect bad HEAD
git bisect good <known-good-commit>
# Git checkouts midpoints; run your test at each to narrow down
# View what changed recently
git log --oneline -20
git diff HEAD~5..HEAD -- src/
# Find who last changed a specific line
git blame src/services/task.ts
# Search commit messages for a keyword
git log --grep="validation" --oneline
Common Rationalizations
| Rationalization | Reality |
|---|---|
| "I'll commit when the feature is done" | One giant commit is impossible to review, debug, or revert. Commit each slice. |
| "The message doesn't matter" | Messages are documentation. Future you (and future agents) will need to understand what changed and why. |
| "I'll squash it all later" | Squashing destroys the development narrative. Prefer clean incremental commits from the start. |
| "Branches add overhead" | Branches are free and prevent conflicting work from colliding. Use them. |
| "I don't need a .gitignore" | Until .env with production secrets gets committed. Set it up immediately. |
Red Flags
- Large uncommitted changes accumulating
- Commit messages like "fix", "update", "misc"
- Formatting changes mixed with behavior changes
- No
.gitignorein the project - Committing
node_modules/,.env, or build artifacts - Long-lived branches that diverge significantly from main
- Force-pushing to shared branches
Verification
For every commit:
- [ ] Commit does one logical thing
- [ ] Message explains the why, follows type conventions
- [ ] Tests pass before committing
- [ ] No secrets in the diff
- [ ] No formatting-only changes mixed with behavior changes
- [ ]
.gitignorecovers standard exclusions