Communitygithub.com

git-workflow

Gitワークフローパターン。ブランチ戦略、コミット規約、マージとリベースの使い分け、コンフリクト解決、多様なチームサイズ向けの協調開発ベストプラクティスを提供します。ブランチ戦略の選択、コミット規約の作成、マージとリベースの判断、コンフリクト解決時に使用します。

git-workflow とは?

このスキルは、Gitのバージョン管理、ブランチ戦略、協調開発に関する包括的なベストプラクティスを提供します。GitFlow、トランクベース開発、GitHub Flowの主要なブランチ戦略を比較し、チームサイズやリリース頻度に応じた選択基準を示します。また、Conventional Commits形式に基づくコミットメッセージの書き方、マージとリベースの適切な使い分け、プルリクエストのテンプレートやコードレビューチェックリスト、コンフリクト解決の実践的な手順をカバーします。Gitの設定やエイリアス、.gitignoreパターン、フック、よくあるアンチパターンも含まれており、初心者から経験豊富な開発者まで、あらゆるGitユーザーが効率的なワークフローを構築するのに役立ちます。

対応~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/affaan-m/ECC/tree/main/skills/git-workflow

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

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

ドキュメント

Gitワークフローパターン

Gitバージョン管理、ブランチ戦略、協調開発のベストプラクティス。

アクティベートすべきタイミング

  • 新しいプロジェクトでGitワークフローを設定するとき
  • ブランチ戦略(GitFlow、トランクベース、GitHub Flow)を決めるとき
  • コミットメッセージやプルリクエストの説明を書くとき
  • マージコンフリクトを解決するとき
  • リリースとバージョンタグを管理するとき
  • 新しいチームメンバーにGitプラクティスをオンボーディングするとき

ブランチ戦略

GitHub Flow(シンプル、ほとんどのチームにおすすめ)

継続的デプロイと小〜中規模チームに最適。

main (保護、常にデプロイ可能)
  │
  ├── feature/user-auth      → PR → mainにマージ
  ├── feature/payment-flow   → PR → mainにマージ
  └── fix/login-bug          → PR → mainにマージ

ルール:

  • main は常にデプロイ可能
  • main からフィーチャーブランチを作成
  • レビュー準備ができたらプルリクエストを開く
  • 承認後、CIが通ったら main にマージ
  • マージ後すぐにデプロイ

トランクベース開発(高速度チーム向け)

強力なCI/CDとフィーチャーフラグを持つチームに最適。

main (トランク)
  │
  ├── 短命なフィーチャーブランチ(最大1-2日)
  ├── 短命なフィーチャーブランチ
  └── 短命なフィーチャーブランチ

ルール:

  • 全員が main または非常に短命なブランチにコミット
  • フィーチャーフラグで未完成の作業を隠す
  • マージ前にCIがパスすること
  • 1日に複数回デプロイ

GitFlow(複雑、リリースサイクル駆動)

スケジュールリリースとエンタープライズプロジェクトに最適。

main (プロダクションリリース)
  │
  └── develop (統合ブランチ)
        │
        ├── feature/user-auth
        ├── feature/payment
        │
        ├── release/1.0.0    → mainとdevelopにマージ
        │
        └── hotfix/critical  → mainとdevelopにマージ

ルール:

  • main にはプロダクション準備完了のコードのみ
  • develop が統合ブランチ
  • フィーチャーブランチは develop から作成し、develop にマージ
  • リリースブランチは develop から作成し、main と develop にマージ
  • ホットフィックスブランチは main から作成し、main と develop の両方にマージ

それぞれの使いどころ

戦略チームサイズリリース頻度最適な環境
GitHub Flow任意継続的SaaS、Webアプリ、スタートアップ
トランクベース5人以上の経験者1日複数回高速度チーム、フィーチャーフラグ
GitFlow10人以上スケジュール制エンタープライズ、規制業界

コミットメッセージ

Conventional Commits形式

<type>(<scope>): <subject>

[optional body]

[optional footer(s)]

タイプ

タイプ使用目的例
feat新機能feat(auth): add OAuth2 login
fixバグ修正fix(api): handle null response in user endpoint
docsドキュメントdocs(readme): update installation instructions
styleフォーマット、コード変更なしstyle: fix indentation in login component
refactorコードリファクタリングrefactor(db): extract connection pool to module
testテスト追加・更新test(auth): add unit tests for token validation
choreメンテナンスタスクchore(deps): update dependencies
perfパフォーマンス改善perf(query): add index to users table
ciCI/CD変更ci: add PostgreSQL service to test workflow
revertコミットの取り消しrevert: revert "feat(auth): add OAuth2 login"

良い例と悪い例

# 悪い例:曖昧で文脈がない
git commit -m "fixed stuff"
git commit -m "updates"
git commit -m "WIP"

# 良い例:明確で具体的、理由を説明
git commit -m "fix(api): retry requests on 503 Service Unavailable

The external API occasionally returns 503 errors during peak hours.
Added exponential backoff retry logic with max 3 attempts.

Closes #123"

コミットメッセージテンプレート

リポジトリルートに .gitmessage を作成:

# <type>(<scope>): <subject>
# # Types: feat, fix, docs, style, refactor, test, chore, perf, ci, revert
# Scope: api, ui, db, auth, etc.
# Subject: imperative mood, no period, max 50 chars
#
# [optional body] - explain why, not what
# [optional footer] - Breaking changes, closes #issue

有効化: git config commit.template .gitmessage

マージ vs リベース

マージ(履歴を保持)

# マージコミットを作成
git checkout main
git merge feature/user-auth

# 結果:
# *   merge commit
# |\
# | * feature commits
# |/
# * main commits

使用すべきとき:

  • フィーチャーブランチを main にマージするとき
  • 正確な履歴を保持したいとき
  • 複数人がブランチで作業したとき
  • ブランチがプッシュ済みで、他の人がそのブランチをベースに作業している可能性があるとき

リベース(線形履歴)

# フィーチャーブランチのコミットをターゲットブランチの上に書き換える
git checkout feature/user-auth
git rebase main

# 結果:
# * feature commits (rewritten)
# * main commits

使用すべきとき:

  • ローカルのフィーチャーブランチを最新の main で更新するとき
  • 線形でクリーンな履歴にしたいとき
  • ブランチがローカルのみ(プッシュされていない)
  • 自分だけがそのブランチで作業しているとき

リベースワークフロー

# PR前にフィーチャーブランチを最新のmainで更新
git checkout feature/user-auth
git fetch origin
git rebase origin/main

# コンフリクトがあれば修正
# テストはまだパスするはず

# 強制プッシュ(自分だけの貢献者の場合のみ)
git push --force-with-lease origin feature/user-auth

リベースしてはいけないとき

# 以下のブランチでは決してリベースしないこと:
- 共有リポジトリにプッシュ済みのブランチ
- 他の人がベースにしているブランチ
- 保護されたブランチ(main, develop)
- すでにマージされたブランチ

# 理由: リベースは履歴を書き換え、他の人の作業を壊す

プルリクエストワークフロー

PRタイトル形式

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

例:
feat(auth): add SSO support for enterprise users
fix(api): resolve race condition in order processing
docs(api): add OpenAPI specification for v2 endpoints

PR説明テンプレート

## 何を

このPRが何をするかの簡単な説明。

## なぜ

動機とコンテキストを説明。

## 方法

注目すべき主要な実装の詳細。

## テスト

- [ ] 単体テスト追加/更新
- [ ] 統合テスト追加/更新
- [ ] 手動テスト実施

## スクリーンショット(該当する場合)

UI変更の前/後のスクリーンショット。

## チェックリスト

- [ ] コードがプロジェクトのスタイルガイドラインに従っている
- [ ] 自己レビュー完了
- [ ] 複雑なロジックにコメントを追加
- [ ] ドキュメント更新
- [ ] 新しい警告が追加されていない
- [ ] テストがローカルでパス
- [ ] 関連するイシューがリンクされている

Closes #123

コードレビューチェックリスト

レビュアー向け:

  • コードは問題を解決しているか?
  • 処理されていないエッジケースはないか?
  • コードは読みやすく、保守しやすいか?
  • 十分なテストがあるか?
  • セキュリティ上の懸念はないか?
  • コミット履歴はクリーンか?(必要に応じてスカッシュ済みか)

作成者向け:

  • レビュー依頼前に自己レビュー完了
  • CIがパス(テスト、リント、型チェック)
  • PRサイズが妥当(理想的には500行未満)
  • 単一の機能/修正に関連している
  • 説明が変更内容を明確に説明している

コンフリクト解決

コンフリクトの特定

# マージ前にコンフリクトを確認
git checkout main
git merge feature/user-auth --no-commit --no-ff

# コンフリクトがある場合、Gitが表示:
# CONFLICT (content): Merge conflict in src/auth/login.ts
# Automatic merge failed; fix conflicts and then commit the result.

コンフリクトの解決

# コンフリクトしているファイルを確認
git status

# ファイル内のコンフリクトマーカーを確認
# <<<<<<< HEAD
# content from main
# =======
# content from feature branch
# >>>>>>> feature/user-auth

# オプション1: 手動解決
# ファイルを編集し、マーカーを削除し、正しい内容を保持

# オプション2: マージツールを使用
git mergetool

# オプション3: 一方を受け入れる
git checkout --ours src/auth/login.ts    # mainバージョンを保持
git checkout --theirs src/auth/login.ts  # フィーチャーバージョンを保持

# 解決後、ステージしてコミット
git add src/auth/login.ts
git commit

コンフリクト防止戦略

# 1. フィーチャーブランチを小さく、短命に保つ
# 2. 頻繁にmainにリベースする
git checkout feature/user-auth
git fetch origin
git rebase origin/main

# 3. 共有ファイルに触れることについてチームとコミュニケーション
# 4. 長命ブランチの代わりにフィーチャーフラグを使用
# 5. PRを迅速にレビューしてマージする

ブランチ管理

命名規則

# フィーチャーブランチ
feature/user-authentication
feature/JIRA-123-payment-integration

# バグ修正
fix/login-redirect-loop
fix/456-null-pointer-exception

# ホットフィックス(本番問題)
hotfix/critical-security-patch
hotfix/database-connection-leak

# リリース
release/1.2.0
release/2024-01-hotfix

# 実験/POC
experiment/new-caching-strategy
poc/graphql-migration

ブランチのクリーンアップ

# マージ済みのローカルブランチを削除
git branch --merged main | grep -v "^\*\|main" | xargs -n 1 git branch -d

# 削除されたリモートブランチのリモート追跡参照を削除
git fetch -p

# ローカルブランチを削除
git branch -d feature/user-auth  # 安全な削除(マージ済みの場合のみ)
git branch -D feature/user-auth  # 強制削除

# リモートブランチを削除
git push origin --delete feature/user-auth

スタッシュワークフロー

# 作業中の変更を保存
git stash push -m "WIP: user authentication"

# スタッシュ一覧
git stash list

# 最新のスタッシュを適用
git stash pop

# 特定のスタッシュを適用
git stash apply stash@{2}

# スタッシュを削除
git stash drop stash@{0}

リリース管理

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

MAJOR.MINOR.PATCH

MAJOR: 互換性のない変更
MINOR: 新機能、後方互換性あり
PATCH: バグ修正、後方互換性あり

例:
1.0.0 → 1.0.1 (patch: バグ修正)
1.0.1 → 1.1.0 (minor: 新機能)
1.1.0 → 2.0.0 (major: 互換性のない変更)

リリースの作成

# 注釈付きタグを作成
git tag -a v1.2.0 -m "Release v1.2.0

Features:
- Add user authentication
- Implement password reset

Fixes:
- Resolve login redirect issue

Breaking Changes:
- None"

# タグをリモートにプッシュ
git push origin v1.2.0

# タグ一覧
git tag -l

# タグを削除
git tag -d v1.2.0
git push origin --delete v1.2.0

チェンジログの生成

# コミットからチェンジログを生成
git log v1.1.0..v1.2.0 --oneline --no-merges

# または conventional-changelog を使用
npx conventional-changelog -i CHANGELOG.md -s

Git設定

必須設定

# ユーザーID
git config --global user.name "Your Name"
git config --global user.email "[email protected]"

# デフォルトのブランチ名
git config --global init.defaultBranch main

# pull動作(マージの代わりにリベース)
git config --global pull.rebase true

# push動作(現在のブランチのみをプッシュ)
git config --global push.default current

# タイプミスの自動修正
git config --global help.autocorrect 1

# より良いdiffアルゴリズム
git config --global diff.algorithm histogram

# カラー出力
git config --global color.ui auto

便利なエイリアス

# ~/.gitconfig に追加
[alias]
    co = checkout
    br = branch
    ci = commit
    st = status
    unstage = reset HEAD --
    last = log -1 HEAD
    visual = log --oneline --graph --all
    amend = commit --amend --no-edit
    wip = commit -m "WIP"
    undo = reset --soft HEAD~1
    contributors = shortlog -sn

Gitignoreパターン

# 依存関係
node_modules/
vendor/

# ビルド出力
dist/
build/
*.o
*.exe

# 環境ファイル
.env
.env.local
.env.*.local

# IDE
.idea/
.vscode/
*.swp
*.swo

# OSファイル
.DS_Store
Thumbs.db

# ログ
*.log
logs/

# テストカバレッジ
coverage/

# キャッシュ
.cache/
*.tsbuildinfo

一般的なワークフロー

新機能の開始

# 1. mainブランチを更新
git checkout main
git pull origin main

# 2. フィーチャーブランチを作成
git checkout -b feature/user-auth

# 3. 変更を加えてコミット
git add .
git commit -m "feat(auth): implement OAuth2 login"

# 4. リモートにプッシュ
git push -u origin feature/user-auth

# 5. GitHub/GitLabでプルリクエストを作成

新しい変更でPRを更新

# 1. 追加の変更を加える
git add .
git commit -m "feat(auth): add error handling"

# 2. 更新をプッシュ
git push origin feature/user-auth

フォークを上流と同期

# 1. 上流リモートを追加(一度だけ)
git remote add upstream https://github.com/original/repo.git

# 2. 上流をフェッチ
git fetch upstream

# 3. upstream/main を自分のmainにマージ
git checkout main
git merge upstream/main

# 4. 自分のフォークにプッシュ
git push origin main

ミスの取り消し

# 最後のコミットを取り消す(変更を保持)
git reset --soft HEAD~1

# 最後のコミットを取り消す(変更を破棄)
git reset --hard HEAD~1

# リモートにプッシュした最後のコミットを取り消す
git revert HEAD
git push origin main

# 特定のファイルの変更を取り消す
git checkout HEAD -- path/to/file

# 最後のコミットメッセージを修正
git commit --amend -m "New message"

# 最後のコミットにファイルを追加し忘れた場合
git add forgotten-file
git commit --amend --no-edit

Gitフック

Pre-Commitフック

#!/bin/bash
# .git/hooks/pre-commit

# リントを実行
npm run lint || exit 1

# テストを実行
npm test || exit 1

# シークレットをチェック
if git diff --cached | grep -E '(password|api_key|secret)'; then
    echo "シークレットが検出されました。コミットを中止します。"
    exit 1
fi

Pre-Pushフック

#!/bin/bash
# .git/hooks/pre-push

# 全テストスイートを実行
npm run test:all || exit 1

# console.log文をチェック
if git diff origin/main | grep -E 'console\.log'; then
    echo "プッシュする前にconsole.log文を削除してください。"
    exit 1
fi

アンチパターン

# 悪い例: mainに直接コミット
git checkout main
git commit -m "fix bug"

# 良い例: フィーチャーブランチとPRを使用

# 悪い例: シークレットをコミット
git add .env  # APIキーを含む

# 良い例: .gitignoreに追加し、環境変数を使用

# 悪い例: 巨大なPR(1000行以上)
# 良い例: より小さく焦点を絞ったPRに分割

# 悪い例: "update" コミットメッセージ
git commit -m "update"
git commit -m "fix"

# 良い例: 説明的なメッセージ
git commit -m "fix(auth): resolve redirect loop after login"

# 悪い例: 公開履歴の書き換え
git push --force origin main

# 良い例: 公開ブランチにはrevertを使用
git revert HEAD

# 悪い例: 長命なフィーチャーブランチ(数週間/数ヶ月)
# 良い例: ブランチを短期間(数日)に保ち、頻繁にリベース

# 悪い例: コンフリクトを無視する(すべてoursを受け入れる)
git merge -X theirs feature/branch

# 良い例: コンフリクトを適切に解決する

# 悪い例: タグのみのリリース、チェンジログなし
# 良い例: 変更を文書化する

# 悪い例: レビューなしでPRをマージ
# 良い例: 常にコードレビューを必須にする

Individual skills in this repo

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

accessibility

Design, implement, and audit inclusive digital products using WCAG 2.2 Level AA. Use when building or auditing UI that must meet WCAG 2.2 Level AA, or when reviewing a change for keyboard, contrast, or screen-reader support.

affaan-m/content-engine

Create platform-native content systems for X, LinkedIn, TikTok, YouTube, newsletters, and repurposed multi-platform campaigns. Use when the user wants social posts, threads, scripts, content calendars, or one source asset adapted cleanly across platforms.

affaan-m/ECC

Multi-platform content distribution across X, LinkedIn, Threads, and Bluesky. Adapts content per platform using content-engine patterns. Never posts identical content cross-platform. Use when the user wants to distribute content across social platforms.

affaan-m/fal-ai-media

Unified media generation via fal.ai MCP — image, video, and audio. Covers text-to-image (Nano Banana), text/image-to-video (Seedance, Kling, Veo 3), text-to-speech (CSM-1B), and video-to-audio (ThinkSound). Use when the user wants to generate images, videos, or audio with AI.

affaan-m/manim-video

日本語翻訳:このファイルは manim-video 用の日本語翻訳が必要です

affaan-m/remotion-video-creation

Remotion のベストプラクティス - React で動画を作成する。3D、アニメーション、音声、字幕、チャート、トランジションなどをカバーするドメイン固有の29のルール。

affaan-m/video-editing

AI-assisted video editing workflows for cutting, structuring, and augmenting real footage. Covers the full pipeline from raw capture through FFmpeg, Remotion, ElevenLabs, fal.ai, and final polish in Descript or CapCut. Use when the user wants to edit video, cut footage, create vlogs, or build video content.

agent-architecture-audit

Full-stack diagnostic for agent and LLM applications. Audits the 12-layer agent stack for wrapper regression, memory pollution, tool discipline failures, hidden repair loops, and rendering corruption. Produces severity-ranked findings with code-first fixes. Essential for developers building agent applications, autonomous loops, or any LLM-powered feature. Use when an agent or LLM feature misbehaves and the failing layer is unknown, or before shipping an agent stack.

agent-eval

Head-to-head comparison of coding agents (Claude Code, Aider, Codex, etc.) on custom tasks with pass rate, cost, time, and consistency metrics. Use when choosing between coding agents, or when a change to an agent setup needs measured pass rate, cost, and time rather than an impression.

agent-harness-construction

Design and optimize AI agent action spaces, tool definitions, and observation formatting for higher completion rates. Use when defining or revising an agent

agentic-engineering

Operate as an agentic engineer using eval-first execution, decomposition, and cost-aware model routing. Use when planning or executing engineering work that agents will carry out end to end.

agentic-os

Build persistent multi-agent operating systems on Claude Code. Covers kernel architecture, specialist agents, slash commands, file-based memory, scheduled automation, and state management without external databases. Use when building a persistent multi-agent system on Claude Code with its own memory, commands, and scheduling.

agent-introspection-debugging

Structured self-debugging workflow for AI agent failures using capture, diagnosis, contained recovery, and introspection reports. Use when an agent run fails and you need a reproducible diagnosis instead of a retry.

agent-payment-x402

Add x402 payment execution to AI agents with per-task budgets, spending controls, and non-custodial wallets. Supports Base through agentwallet-sdk and X Layer through OKX Payments / OKX Agent Payments Protocol. Use when an agent must pay for something itself and needs per-task budgets, spending controls, and a non-custodial wallet.

agent-self-evaluation

Use after completing any non-trivial task. The agent self-rates its output on 5 axes — accuracy, completeness, clarity, actionability, conciseness — with concrete evidence per criterion. Produces a structured 1-5 scorecard with specific improvement suggestions.

agent-sort

Build an evidence-backed ECC install plan for a specific repo by sorting skills, commands, rules, hooks, and extras into DAILY vs LIBRARY buckets using parallel repo-aware review passes. Use when ECC should be trimmed to what a project actually needs instead of loading the full bundle.

ai-first-engineering

Engineering operating model for teams where AI agents generate a large share of implementation output. Use when setting team process, review gates, or ownership rules for a codebase largely written by agents.

ai-regression-testing

Regression testing strategies for AI-assisted development. Sandbox-mode API testing without database dependencies, automated bug-check workflows, and patterns to catch AI blind spots where the same model writes and reviews code. Use when adding regression coverage to AI-assisted code, or when the same model both wrote and reviewed a change.

android-clean-architecture

Clean Architecture patterns for Android and Kotlin Multiplatform projects — module structure, dependency rules, UseCases, Repositories, and data layer patterns. Use when structuring modules, layers, or data flow in an Android or KMP project.

angular-developer

Generates Angular code and provides architectural guidance. Trigger when creating projects, components, or services, or for best practices on reactivity (signals, linkedSignal, resource), forms, dependency injection, routing, SSR, accessibility (ARIA), animations, styling (component styles, Tailwind CSS), testing, or CLI tooling.

関連スキル