git-workflow について
git-workflowは、コミット、ブランチ、プルリクエスト、履歴管理、共同作業を扱う開発者向けのGit実践スキルです。優先度別のルールに加え、例とレビュー指摘の形式を示します。
主な機能
- 01コミットメッセージの規約と例
- 02ブランチ命名と戦略
- 03プルリクエストの実践
- 04履歴管理と競合への対応
- 05共同作業とGit Hooksの指針
活用シーン
- 01一貫したコミットメッセージの作成
- 02ブランチとリリース手順の計画
- 03プルリクエストのレビューと分割
- 04履歴の整理とマージ競合の解決
インストール
コマンドをコピーしてターミナルで実行します。
$
npx skills add https:/ / github.com/ asyrafhussin/ agent-skills --skill git-workflowインストール後、Claude Code で/git-workflowを入力して読み込まれたか確認します。
同梱ファイル
SKILL.md と一緒にインストールされる参考資料やスクリプト。
AGENTS.mdmetadata.jsonREADME.mdrules/_sections.md_template.mdbranch-delete-merged.mdbranch-feature-workflow.mdbranch-main-protected.mdbranch-monorepo.mdbranch-naming-convention.mdbranch-release-strategy.mdbranch-short-lived.mdbranch-workflow-strategies.mdcollab-code-review.mdcollab-communication.mdcollab-conflict-resolution.mdcollab-gitignore.mdcommit-atomic-changes.mdcommit-body-context.mdcommit-breaking-changes.mdcommit-conventional-format.mdcommit-git-hooks.mdcommit-imperative-mood.mdcommit-meaningful-subject.mdcommit-references.mdhistory-clean-commits.mdhistory-no-force-push.mdhistory-rebase-vs-merge.mdhistory-tags-releases.mdhistory-worktree.md詳細
Git ワークフロー
Git のベストプラクティス、コミット規約、ブランチ戦略、プルリクエストのワークフローについて説明します。クリーンで有用な Git 履歴を維持するためのガイドラインです。
適用するタイミング
以下の場合に、これらのガイドラインを参照してください。
- コミットメッセージを書くとき
- ブランチを作成するとき
- Git ワークフローを設定するとき
- プルリクエストをレビューするとき
- Git 履歴を維持するとき
優先度別のルールカテゴリー
| 優先度 | カテゴリー | 影響度 | プレフィックス |
|---|---|---|---|
| 1 | コミットメッセージ | CRITICAL | commit- |
| 2 | ブランチ戦略 | HIGH | branch- |
| 3 | プルリクエスト | HIGH | pr- |
| 4 | 履歴管理 | MEDIUM | history- |
| 5 | コラボレーション | MEDIUM | collab- |
クイックリファレンス
1. コミットメッセージ(CRITICAL)
commit-conventional- Conventional Commits を使用するcommit-atomic- アトミックなコミットを作成する(論理的な変更を1つずつ)commit-present-tense- 命令形の現在形を使用するcommit-meaningful- 説明的で意味のあるメッセージを書くcommit-body- 複雑な変更には本文を追加するcommit-references- イシューやチケットを参照するcommit-git-hooks- Husky + commitlint で規約を徹底する
2. ブランチ戦略(HIGH)
branch-naming- 一貫性のあるブランチ命名を行うbranch-feature- フィーチャーブランチのワークフローを使用するbranch-main-protected- main ブランチを保護するbranch-short-lived- ブランチを短期間で運用するbranch-delete-merged- マージ済みのブランチを削除するbranch-release- リリースブランチ戦略branch-workflow-strategies- GitFlow と GitHub Flow と Trunk-Based の比較branch-monorepo- モノレポの Git ワークフロー
3. プルリクエスト(HIGH)
pr-small- PR を小さく、焦点を絞ったものにするpr-description- 明確な説明を書くpr-reviewers- 適切なレビュアーを依頼するpr-ci-pass- CI が成功することを確認するpr-squash- 適切な場合にスカッシュするpr-draft- 作業中の変更や早期フィードバックにはドラフト PR を使用する
4. 履歴管理(MEDIUM)
history-rebase- リベースとマージを使い分けるhistory-no-force-push- 共有ブランチへの強制プッシュを避けるhistory-clean- 履歴をクリーンに保つhistory-tags- リリースにタグを使用するhistory-worktree- git worktree で複数のブランチを扱う
5. コラボレーション(MEDIUM)
collab-code-review- 効果的なコードレビューcollab-conflicts- マージコンフリクトに対処するcollab-communication- 変更について共有するcollab-gitignore- .gitignore のベストプラクティス
基本ガイドライン
Conventional Commits
# Format
<type>(<scope>): <subject>
<body>
<footer>
種類
| 種類 | 説明 |
|---|---|
feat | 新機能 |
fix | バグ修正 |
docs | ドキュメントのみ |
style | フォーマット変更、コードの変更なし |
refactor | 機能追加やバグ修正を伴わないコード変更 |
perf | パフォーマンス改善 |
test | テストの追加・更新 |
chore | メンテナンス、依存関係 |
ci | CI/CD の変更 |
build | ビルドシステムの変更 |
revert | 以前のコミットを取り消す |
例
# ✅ Good commit messages
feat(auth): add password reset functionality
fix(cart): resolve quantity update race condition
docs(readme): add installation instructions
refactor(api): extract validation into middleware
test(user): add unit tests for registration
chore(deps): update dependencies to latest versions
# With body and footer
feat(orders): implement order cancellation
Add ability for users to cancel pending orders within 24 hours.
Cancelled orders trigger refund process automatically.
Closes #123
BREAKING CHANGE: Order status enum now includes 'cancelled'
# ❌ Bad commit messages
fix bug
update
WIP
asdfasdf
changes
misc fixes
ブランチ命名
# ✅ Good branch names
feature/user-authentication
feature/JIRA-123-password-reset
fix/cart-total-calculation
fix/issue-456-login-redirect
hotfix/security-patch
docs/api-documentation
refactor/database-queries
chore/update-dependencies
# ❌ Bad branch names
new-feature
john-branch
test
fix
temp
asdf
ブランチワークフロー
# Main branches
main # Production-ready code
develop # Integration branch (optional)
# Supporting branches
feature/* # New features
fix/* # Bug fixes
hotfix/* # Production hotfixes
release/* # Release preparation
# Workflow
git checkout main
git pull origin main
git checkout -b feature/user-profile
# Work on feature...
git add .
git commit -m "feat(profile): add profile page"
# Keep branch updated
git fetch origin
git rebase origin/main
# Push and create PR
git push -u origin feature/user-profile
アトミックなコミット
# ❌ One commit doing multiple things
git commit -m "Add login, fix header, update deps"
# ✅ Separate commits for each change
git commit -m "feat(auth): add login page"
git commit -m "fix(header): correct navigation alignment"
git commit -m "chore(deps): update React to v18.2"
こまめにコミットし、定期的にプッシュする
# ✅ Small, frequent commits
git commit -m "feat(cart): add product to cart"
git commit -m "feat(cart): display cart item count"
git commit -m "feat(cart): implement remove item"
git commit -m "test(cart): add unit tests"
# ❌ One massive commit
git commit -m "feat: implement entire shopping cart"
プルリクエストのベストプラクティス
PR タイトル
# Format (like commit)
<type>(<scope>): <description>
# ✅ Good PR titles
feat(auth): implement OAuth2 login
fix(checkout): resolve payment processing error
docs(api): add endpoint documentation
# ❌ Bad PR titles
Update
Fix stuff
WIP
PR 説明テンプレート
## Summary
Brief description of what this PR does.
## Changes
- Added user authentication endpoints
- Implemented JWT token generation
- Added password hashing with bcrypt
## Testing
- [ ] Unit tests pass
- [ ] Integration tests pass
- [ ] Manual testing completed
## Screenshots (if UI changes)
[Add screenshots here]
## Related Issues
Closes #123
Related to #456
## Checklist
- [ ] Code follows project conventions
- [ ] Self-review completed
- [ ] Tests added/updated
- [ ] Documentation updated
PR を小さく保つ
# ✅ Focused PRs
PR #1: Add user model and migrations
PR #2: Implement user registration endpoint
PR #3: Add email verification
PR #4: Implement login/logout
# ❌ Large unfocused PR
PR #1: Add entire user authentication system
(2000+ lines, 50+ files)
リベースとマージ
# ✅ Rebase for feature branches (clean history)
git checkout feature/my-feature
git fetch origin
git rebase origin/main
# Resolve any conflicts
git push --force-with-lease # Only your branch!
# ✅ Merge for integrating to main (preserve context)
git checkout main
git merge --no-ff feature/my-feature
# Creates merge commit, preserves branch history
# ❌ Never force push to shared branches
git push --force origin main # NEVER DO THIS
インタラクティブリベース(整理)
# Before pushing, clean up commits
git rebase -i HEAD~5
# In editor:
pick abc123 feat: add login page
squash def456 fix typo
squash ghi789 more fixes
pick jkl012 feat: add logout
# Result: clean history with meaningful commits
コンフリクトへの対処
# During rebase
git rebase origin/main
# CONFLICT in file.ts
# 1. Open conflicted files
# 2. Resolve conflicts (remove markers)
# 3. Stage resolved files
git add file.ts
# 4. Continue rebase
git rebase --continue
# Or abort if needed
git rebase --abort
Git フック
# .husky/pre-commit
#!/bin/sh
npm run lint
npm run test:unit
# .husky/commit-msg
#!/bin/sh
npx commitlint --edit $1
# commitlint.config.js
module.exports = {
extends: ['@commitlint/config-conventional'],
};
リリースへのタグ付け
# Semantic versioning tags
git tag -a v1.0.0 -m "Release version 1.0.0"
git push origin v1.0.0
# List tags
git tag -l "v1.*"
# Tag format
v1.0.0 # Major.Minor.Patch
v1.0.0-beta.1 # Pre-release
v1.0.0-rc.1 # Release candidate
.gitignore のベストプラクティス
# Dependencies
node_modules/
vendor/
# Build outputs
dist/
build/
.next/
# Environment files
.env
.env.local
.env.*.local
# IDE
.idea/
.vscode/
*.swp
# OS files
.DS_Store
Thumbs.db
# Logs
*.log
logs/
# Test coverage
coverage/
# Cache
.cache/
*.cache
便利な Git コマンド
# View commit history
git log --oneline --graph --all
# See what changed
git diff --staged
git diff HEAD~1
# Undo last commit (keep changes)
git reset --soft HEAD~1
# Discard local changes
git checkout -- file.ts
git restore file.ts # Git 2.23+
# Stash changes
git stash
git stash pop
git stash list
# Cherry-pick commit
git cherry-pick abc123
# Find who changed a line
git blame file.ts
# Search commits
git log --grep="fix"
git log -S "functionName"
出力形式
Git のプラクティスをレビューする際は、次の形式で調査結果を出力してください。
[category] Description of issue or suggestion
例:
[commit] Use imperative mood: "Add feature" not "Added feature"
[branch] Branch name 'test' should follow pattern: feature/description
[pr] PR is too large (50+ files), consider splitting
使い方
詳しい説明については、個別のルールファイルを参照してください。
rules/commit-conventional-format.md
rules/branch-naming-convention.md
rules/pr-small-focused.md
参考資料
- Git 公式ドキュメント - Git の包括的なドキュメント
- Pro Git Book - Pro Git の完全版
- Conventional Commits - コミットメッセージの仕様
- GitHub Flow - 軽量なワークフロー
- Git のコミットメッセージの書き方 - コミットメッセージのガイド
- Google のコードレビューの実践 - コードレビューのベストプラクティス
有名プロジェクトの事例
優れた Git の実践を行っているプロジェクトから学びましょう。
- Linux Kernel - 詳細なコミットメッセージとパッチのワークフロー
- React - Conventional Commits と徹底した PR レビュー
- Vue.js - 整理されたコミット履歴と優れた PR テンプレート
- TypeScript - 構造化されたブランチ運用と明確なリリースプロセス
- Next.js - Conventional Commits と自動リリース
設定例
Commitlint
// commitlint.config.js
module.exports = {
extends: ['@commitlint/config-conventional'],
rules: {
'type-enum': [
2,
'always',
['feat', 'fix', 'docs', 'style', 'refactor', 'perf', 'test', 'chore', 'ci', 'build', 'revert']
],
'subject-max-length': [2, 'always', 72],
'body-max-line-length': [2, 'always', 100]
}
};
Husky Git フック
# .husky/commit-msg
#!/bin/sh
npx commitlint --edit $1
# .husky/pre-commit
#!/bin/sh
npm run lint
npm test
GitHub PR テンプレート
# .github/PULL_REQUEST_TEMPLATE.md
## Summary
Brief description of changes
## Changes
- List key changes
- One per line
## Testing
- [ ] Unit tests pass
- [ ] Integration tests pass
- [ ] Manual testing completed
## Related
Closes #issue-number
メタデータ
スキルバージョン: 1.2.0 最終更新日: 2026-03-08 ルール総数: 31 カテゴリー: 5(コミットメッセージ、ブランチ戦略、プルリクエスト、履歴管理、コラボレーション)
対応環境:
- Git 2.0+
- GitHub、GitLab、Bitbucket、Azure DevOps
推奨ツール:
- Git - バージョン管理システム
- GitHub CLI - GitHub のコマンドラインツール
- Commitlint - コミットメッセージのリンター
- Husky - Git フック
- Semantic Release - バージョン管理の自動化
ライセンス
MIT ライセンスです。このスキルは、教育および開発目的で現状のまま提供されます。
コメント
Markdown 対応