Communityコーディング&開発github.com

Git ワークフローとバージョニング

Git のワークフローとバージョニングを構造化します。コード変更、コミット、ブランチ、コンフリクト解決、クリーンなアトミックコミットへの分割、プルリクエスト、プッシュ、リリースカット、セマンティックバージョン選定、タグ付け、チェンジログ作成など、あらゆる場面で使用します。

Git ワークフローとバージョニング とは?

このスキルは、AIエージェントとチーム開発に最適化されたGitの実践的なワークフローとバージョニングのガイドです。トランクベース開発を推奨し、短命なフィーチャーブランチ(1〜3日以内にマージ)とアトミックコミットを基本とします。セマンティックバージョニング(MAJOR.MINOR.PATCH)に基づくリリースタグと人間向けのチェンジログの書き方も詳しく解説しており、コードの変更履歴を管理しやすくします。また、git worktreeによる並列作業や、セーブポイントパターンによる安全な作業進行、プリコミットフックによる品質チェックの自動化など、AIエージェントの高速なコード生成に耐える堅牢なバージョン管理を実現します。Claude CodeやCursorなどのAIエージェントツールで利用でき、スキル名は「alfathafp/portofolio-web-design」ですが、内容は汎用的なGitワークフロー管理です。

対応~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/alfathafp/portofolio-web-design/tree/HEAD/.agents/skills/git-workflow-and-versioning

Installed? Explore more コーディング&開発 skills: steipete/bluebubbles, steipete/eightctl, steipete/blucli · View all 6 →

お気に入りのAIに質問する

このエージェントスキルを事前に読み込んだ状態で新しいチャットを開きます。

ドキュメント

Git ワークフローとバージョニング は何をしますか?

概要

Git はあなたのセーフティネットです。コミットはセーブポイント、ブランチはサンドボックス、履歴はドキュメントとして扱ってください。AIエージェントが高速でコードを生成する時代、規律あるバージョン管理こそが変更を管理可能で、レビュー可能で、元に戻せる状態に保つ仕組みです。

使用するタイミング

常に。すべてのコード変更はGitを通して行います。

核となる原則

トランクベース開発(推奨)

main を常にデプロイ可能な状態に保ちます。短期間(1〜3日以内)でマージするフィーチャーブランチで作業します。長期生存する開発ブランチは隠れたコストです — 分岐し、マージコンフリクトを生み、統合を遅らせます。DORAの研究は、トランクベース開発が高パフォーマンスなエンジニアリングチームと相関することを一貫して示しています。

main ──●──●──●──●──●──●──●──●──●──  (常にデプロイ可能)
        ╲      ╱  ╲    ╱
         ●──●─╱    ●──╱    ← 短期間のフィーチャーブランチ(1〜3日)

これが推奨されるデフォルトです。gitflowや長期生存ブランチを使用するチームは、原則(アトミックコミット、小さな変更、説明的なメッセージ)を各自のブランチモデルに適応させることができます — コミットの規律は、特定のブランチ戦略よりも重要です。

  • Dev ブランチはコストです。 ブランチが生きている日数が増えるごとに、マージリスクが蓄積されます。
  • リリースブランチは許容されます。 main を進めながらリリースを安定させる必要がある場合。
  • フィーチャーフラグ > 長期ブランチ。 不完全な作業はブランチに何週間も保持するのではなく、フラグの背後にデプロイすることを推奨します。

1. 早期にコミット、頻繁にコミット

成功した各インクリメントは、それぞれ独立したコミットにします。大きな未コミットの変更をため込まないでください。

作業パターン:
  スライスを実装 → テスト → 確認 → コミット → 次のスライス

これではない:
  すべてを実装 → うまくいくことを願う → 巨大なコミット

コミットはセーブポイントです。次の変更で何かが壊れた場合、最後に正常だった状態に即座に戻せます。

2. アトミックコミット

各コミットは1つの論理的なことを行います:

# 良い: 各コミットが自己完結している
git log --oneline
a1b2c3d タスク作成エンドポイントを追加(バリデーション付き)
d4e5f6g タスク作成フォームコンポーネントを追加
h7i8j9k フォームをAPIに接続し、ローディング状態を追加
m1n2o3p タスク作成テストを追加(単体 + 統合)

# 悪い: すべてが混ざっている
git log --oneline
x1y2z3a タスク機能追加、サイドバー修正、依存関係更新、ユーティリティリファクタリング

3. 説明的なメッセージ

コミットメッセージは「何を」ではなく「なぜ」を説明します:

# 良い: 意図を説明している
feat: 登録エンドポイントにメールバリデーションを追加

無効なメール形式がデータベースに到達するのを防ぎます。
auth.ts の既存のバリデーションパターンと一貫性を持たせ、
ルートハンドラーレベルで Zod スキーマバリデーションを使用します。

# 悪い: diff から明らかなことを説明している
auth.ts を更新

形式:

<type>: <短い説明>

<オプションの本文: 何をではなくなぜを説明>

タイプ:

  • feat — 新機能
  • fix — バグ修正
  • refactor — バグ修正でも機能追加でもないコード変更
  • test — テストの追加または更新
  • docs — ドキュメントのみ
  • chore — ツール、依存関係、設定

4. 関心事を分離する

フォーマット変更と振る舞いの変更を組み合わせないでください。リファクタリングと機能追加を組み合わせないでください。変更の種類ごとに別々のコミットにし、理想的には別々のPRにします:

# 良い: 関心事を分離
feat: 電話番号バリデーションを登録に追加
refactor: バリデーションロジックを共有ユーティリティに抽出

# 悪い: 関心事が混ざっている
git commit -m "バリデーションをリファクタリングして電話番号フィールドを追加"

リファクタリングと機能作業を分離します。 リファクタリングの変更と機能の変更は2つの異なる変更です — 別々に提出してください。これにより、各変更のレビュー、元に戻し、履歴の理解が容易になります。変数名の変更のような小さなクリーンアップは、レビュアーの判断で機能コミットに含めることができます。

5. 変更のサイズを調整する

コミット/PRあたり約100行を目標にします。約1000行を超える変更は分割する必要があります。大規模な変更を分割する方法については、code-review-and-quality スキルの分割戦略を参照してください。

約100行  → レビューも元に戻すも簡単
約300行  → 単一の論理変更としては許容範囲
約1000行 → より小さな変更に分割

ブランチ戦略

フィーチャーブランチ

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 worktree を使用して複数のブランチを同時に実行します:

# フィーチャーブランチのワークツリーを作成
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を依存関係に追加(gzip圧縮で72KB)— すでに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 フックで自動化:

// package.json (lint-staged + husky を使用)
{
  "lint-staged": {
    "*.{ts,tsx}": ["eslint --fix", "prettier --write"],
    "*.{json,md}": ["prettier --write"]
  }
}

生成ファイルの扱い

  • 生成ファイルをコミットする のは、プロジェクトがそれを期待している場合のみ(例: package-lock.json、Prisma マイグレーション)
  • コミットしない: ビルド出力(dist/、.next/)、環境ファイル(.env)、IDE設定(共有でない限り .vscode/settings.json)
  • .gitignore を持つ: node_modules/、dist/、.env、.env.local、*.pem をカバーすること

デバッグのための Git の使用

# バグを導入したコミットを見つける
git bisect start
git bisect bad HEAD
git bisect good <正常に動作することがわかっているコミット>
# Git が中間地点をチェックアウト; 各地点でテストを実行して絞り込む

# 最近変更された内容を表示
git log --oneline -20
git diff HEAD~5..HEAD -- src/

# 特定の行を最後に変更した人を調べる
git blame src/services/task.ts

# コミットメッセージ内のキーワードを検索
git log --grep="validation" --oneline

リリースとバージョニング

コミットはあなた自身が変更を追跡する方法です。バージョン は、あなたのコードの利用者が変更を追跡する方法です。他の何かがあなたのコードに依存し始めた瞬間 — 別のチーム、公開されたパッケージ、デプロイされたクライアント — 「main の最新」は「何を実行していて、アップグレードしても安全か?」という質問への十分な答えではなくなります。バージョン番号とチェンジログは、それに答える契約です。

セマンティックバージョニング

利用者がいるものには、MAJOR.MINOR.PATCH でバージョン付けし、数字に意味を持たせます:

  MAJOR  破壊的変更 — 利用者はアップグレードするためにコードを変更する必要がある
  MINOR  新機能、後方互換 — アップグレードしても安全
  PATCH  バグ修正、後方互換 — アップグレードしても安全

数字は約束です。コードがそれに一致するようにしてください。利用者が依存していた振る舞いを変える「パッチ」は、変装したメジャーチェンジです(Hyrumの法則 — api-and-interface-design スキルを参照)。変更が破壊的かどうか不明な場合は、破壊的であると仮定してください。思いがけないメジャーバージョンは、壊れた利用者よりもはるかに低コストです。

リリースにタグを付け、タグを真実の源とする

リリースは履歴上の不変のポイントであり、移動するブランチではありません。タグを付けて、常に再現可能にします:

git tag -a v1.4.0 -m "Release 1.4.0"
git push origin v1.4.0

バージョンを散在するファイルに手動で編集するのではなく、タグから派生させます。そうすれば、成果物、タグ、チェンジログが決して矛盾しません。

人間向けのチェンジログを維持する

チェンジログは git log ではありません。利用者向けにキュレーションされた「何が変わって、自分に関係あるか?」という質問への答えです — Added / Changed / Fixed / Deprecated / Removed / Security でグループ化され、最新が上で、各エントリは内部の仕組みではなくユーザーへの影響に基づいて表現されます。

## [1.4.0] - 2025-06-12
### Added
- CSVによる一括タスクインポート
### Fixed
- 繰り返しタスクの期限におけるタイムゾーンのずれ
### Deprecated
- `GET /v1/tasks/all` — ページネーション対応の `GET /v1/tasks` を使用してください(2.0で削除予定)

エントリは変更と同じ変更の中で、影響が新鮮なうちに書いてください — リリース時にコミットの考古学から再構築するのではありません。破壊的変更には移行ノートと非推奨期間を設けてください(deprecation-and-migration スキルに従う)。実際のリリース出荷は shipping-and-launch スキルの仕事です — このセクションはそれに供給するバージョニング契約です。

よくある言い訳

言い訳現実
「機能が完成したらコミットする」1つの巨大なコミットはレビュー、デバッグ、元に戻すのが不可能です。各スライスごとにコミットしてください。
「メッセージは重要じゃない」メッセージはドキュメントです。未来のあなた(そして未来のエージェント)は、何が変わったのか、なぜ変わったのかを理解する必要があります。
「後で全部スカッシュする」スカッシュは開発のストーリーを破壊します。最初からクリーンなインクリメンタルコミットを推奨します。
「ブランチはオーバーヘッドだ」短期間のブランチは無料で、競合する作業の衝突を防ぎます。長期ブランチが問題です — 1〜3日以内にマージしてください。
「後でこの変更を分割する」大きな変更はレビューが難しく、デプロイのリスクが高く、元に戻すのが困難です。提出する前に分割してください。後からではありません。
「.gitignore は必要ない」本番シークレットを含む .env がコミットされるまで。すぐに設定してください。
「小さな修正だからパッチを上げよう」利用者が何を観測できるかを確認してください。彼らが依存していた振る舞いの変更は、diffのサイズに関係なくメジャーです。
「チェンジログはコミットログと同じでいい」コミットはあなたのため。チェンジログは利用者のためのもので、影響でキュレーションされています。生のコミットから生成すると重要なものが埋もれます。
「リリース時にチェンジログを書く」その頃には影響は記憶から再構築され、半分が欠けています。変更と一緒にエントリを書いてください。

レッドフラグ

  • 大きな未コミットの変更が蓄積されている
  • 「fix」「update」「misc」のようなコミットメッセージ
  • フォーマット変更と振る舞いの変更が混ざっている
  • プロジェクトに .gitignore がない
  • node_modules/、.env、ビルド成果物をコミットしている
  • main から大きく乖離した長期生存ブランチ
  • 共有ブランチへのフォースプッシュ
  • マイナーまたはパッチバージョンアップで出荷された破壊的変更
  • タグがないリリース、またはタグと同期していない手動編集されたバージョン番号
  • ユーザー向けリリースにチェンジログエントリがない、またはコミットメッセージをそのままダンプしただけのチェンジログ

検証

すべてのコミットで:

  • コミットは1つの論理的なことを行う
  • メッセージが「なぜ」を説明し、タイプ規約に従っている
  • コミット前にテストが通る
  • diff にシークレットがない
  • フォーマットのみの変更と振る舞いの変更が混ざっていない
  • .gitignore が標準的な除外項目をカバーしている

すべてのリリースで(利用者がいるもの):

  • バージョンアップが変更と一致している: 破壊的→メジャー、追加→マイナー、修正→パッチ
  • リリースにタグが付けられ、バージョンがタグから派生しており、手動編集で同期が取れていない
  • チェンジログに、このバージョンの影響ごとにグループ化された、キュレーションされた人間が読めるエントリがある

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

alfathafp/portofolio-web-design

You MUST use this before any creative work - creating features, building components, adding functionality, modifying behavior, or planning anything new, in software or out of it (a talk, a business, a renovation).

alfathafp/portofolio-web-design

Tests in real browsers via Chrome DevTools MCP. Use when building or debugging anything that runs in a browser. Use when you need to inspect the DOM, capture console errors, analyze network requests, profile performance, or verify visual output with real runtime data. Requires the chrome-devtools MCP server to be configured.

alfathafp/portofolio-web-design

Automates CI/CD pipeline setup. Use when setting up or modifying build and deployment pipelines. Use when you need to automate quality gates, configure test runners in CI, or establish deployment strategies.

alfathafp/portofolio-web-design

Conducts multi-axis code review. Use before merging any change. Use when reviewing code written by yourself, another agent, or a human. Use when you need to assess code quality across multiple dimensions before it enters the main branch. Use when asked to review a diff or a pull request, even when the diff is pasted inline.

alfathafp/portofolio-web-design

Simplifies code for clarity. Use when refactoring code for clarity without changing behavior. Use when code works but is harder to read, maintain, or extend than it should be. Use when reviewing code that has accumulated unnecessary complexity.

alfathafp/portofolio-web-design

Establishes a project's quality bar as a written contract and stops agents quietly lowering it. Interviews the user on which dimensions matter, supplies sane default thresholds when they have no number in mind, records everything in CONSTRAINTS.md, and watches the diff for a weakened bar — new @ts-ignore or eslint-disable suppressions, skipped or deleted tests, assertions stripped out, unimplemented stubs, thresholds edited down. Use when no quality bar is written down, when the user says "set up constraints" or "define our standards", when the user wants dimensions they care about — accessibility, web performance, coverage — set up as enforced constraints, when an agent keeps silencing checks or skipping tests to get to green, when you need a coverage or performance threshold and don't know what number to pick, or when an agent writes more code than anyone will read.

alfathafp/portofolio-web-design

Optimizes agent context setup. Use when starting a new session, when agent output quality degrades, when switching between tasks, or when you need to configure rules files and context for a project.

alfathafp/portofolio-web-design

Guides systematic root-cause debugging. Use when tests fail, builds break, something that worked yesterday broke, behavior doesn't match expectations, or you encounter any unexpected error. Use when you need to figure out what broke and why — a systematic approach to finding and fixing the root cause rather than guessing.

alfathafp/portofolio-web-design

Deploy applications and websites to Vercel. Use when the user requests deployment actions like "deploy my app", "deploy and give me the link", "push this live", or "create a preview deployment".

alfathafp/portofolio-web-design

Manages deprecation and migration. Use when removing old systems, APIs, or features. Use when migrating users from one implementation to another. Use when migrating a database schema in production, such as renaming or dropping a column without downtime (expand/contract). Use when deciding whether to maintain or sunset existing code.

alfathafp/portofolio-web-design

Use when a superpowers session went wrong and your human partner wants to know why — repeated work, ignored plans, stumbles, poor results, a skill that didn't fire, "it took too long", "why is it so expensive", "what is it doing" — or wants to build a bug report for the superpowers maintainers, for the current session or a past one identified by id or path, on any harness.

alfathafp/portofolio-web-design

Use when facing 2+ independent tasks that can be worked on without shared state or sequential dependencies

alfathafp/portofolio-web-design

Records decisions and documentation. Use when you need to document an architecture decision (ADR) or the reasoning behind a design choice, when changing public APIs, shipping features, or when you need to record context that future engineers and agents will need to understand the codebase.

alfathafp/portofolio-web-design

Subjects every non-trivial decision to a fresh-context adversarial review before it stands. Use when you want every assumption cross-examined before proceeding, when stress-testing a plan for hidden failure modes, when correctness matters more than speed, when working in unfamiliar code, when stakes are high (production auth, security-sensitive logic, a high-stakes migration, irreversible operations), or any time a confident output would be cheaper to verify now than to debug later.

alfathafp/portofolio-web-design

Use when executing an implementation plan in the current session as the implementer yourself — your human partner chose inline execution, or no subagent tool is available

alfathafp/portofolio-web-design

Use when implementation is complete, all tests pass, and you need to decide how to integrate the work

alfathafp/portofolio-web-design

Builds production-quality, accessible, responsive user-facing UIs. Use when building or modifying interfaces and pages, creating components, implementing layouts, meeting WCAG accessibility requirements, managing state, or when the output needs to look and feel production-quality rather than AI-generated.

alfathafp/portofolio-web-design

Refines raw ideas into sharp, actionable concepts through structured divergent and convergent thinking. Use when an idea is still vague, when you need to stress-test assumptions before committing to a plan, or when you want to expand options before converging on one. Triggers on "ideate", "refine this idea", or "stress-test my plan".

alfathafp/portofolio-web-design

Delivers changes incrementally in thin, verifiable slices. Use when implementing any feature or change that touches more than one file, or when picking up the next task from a plan. Use when rolling a change out behind a feature flag, when you're about to write a large amount of code at once, or when a task feels too big to land in one step.

alfathafp/portofolio-web-design

Guides stable API and interface design. Use when designing APIs, module boundaries, or any public interface. Use when creating REST or GraphQL endpoints, defining type contracts between modules, or establishing boundaries between frontend and backend.

関連スキル