ブランチ戦略の詳細
🌿 ブランチ戦略の詳細
Section titled “🌿 ブランチ戦略の詳細”各ブランチ戦略の詳細な実践方法とベストプラクティスを解説します。
🌿 Git Flowの詳細
Section titled “🌿 Git Flowの詳細”📋 ブランチの役割
Section titled “📋 ブランチの役割”🚀 mainブランチ:
- 🚀 本番環境のコード
- ✅ 常にデプロイ可能な状態
- 🏷️ タグでバージョン管理
🔧 developブランチ:
- 🔧 開発環境のコード
- 📋 次のリリースに向けた統合ブランチ
- 🌿 featureブランチのマージ先
✨ featureブランチ:
- ✨ 機能開発用
- 🌿 developブランチから分岐
- 🔀 developブランチにマージ
📦 releaseブランチ:
- 📦 リリース準備用
- 🌿 developブランチから分岐
- 🔀 mainブランチとdevelopブランチにマージ
🔥 hotfixブランチ:
- 🔥 緊急修正用
- 🌿 mainブランチから分岐
- 🔀 mainブランチとdevelopブランチにマージ
💡 実践的なワークフロー
Section titled “💡 実践的なワークフロー”✨ 機能開発の流れ:
# 1. developブランチを最新化git checkout developgit pull origin develop
# 2. featureブランチを作成git checkout -b feature/user-authentication develop
# 3. 開発作業git add .git commit -m "ユーザー認証機能を実装"git push -u origin feature/user-authentication
# 4. プルリクエストを作成(developブランチへのマージ)
# 5. レビューと承認
# 6. developブランチにマージgit checkout developgit merge --no-ff feature/user-authenticationgit push origin develop
# 7. featureブランチを削除git branch -d feature/user-authenticationgit push origin --delete feature/user-authenticationリリースの流れ:
# 1. releaseブランチを作成git checkout -b release/v1.0.0 develop
# 2. バージョン番号を更新# package.json、CHANGELOG.mdなどを更新git add .git commit -m "バージョン1.0.0の準備"git push -u origin release/v1.0.0
# 3. バグ修正などgit add .git commit -m "リリース前のバグ修正"git push origin release/v1.0.0
# 4. mainブランチにマージgit checkout maingit merge --no-ff release/v1.0.0git tag -a v1.0.0 -m "リリース v1.0.0"git push origin main --tags
# 5. developブランチにもマージgit checkout developgit merge --no-ff release/v1.0.0git push origin develop
# 6. releaseブランチを削除git branch -d release/v1.0.0git push origin --delete release/v1.0.0ホットフィックスの流れ:
# 1. hotfixブランチを作成git checkout -b hotfix/security-patch main
# 2. 緊急修正git add .git commit -m "セキュリティパッチを適用"git push -u origin hotfix/security-patch
# 3. mainブランチにマージgit checkout maingit merge --no-ff hotfix/security-patchgit tag -a v1.0.1 -m "ホットフィックス v1.0.1"git push origin main --tags
# 4. developブランチにもマージgit checkout developgit merge --no-ff hotfix/security-patchgit push origin develop
# 5. hotfixブランチを削除git branch -d hotfix/security-patchgit push origin --delete hotfix/security-patchGitHub Flowの詳細
Section titled “GitHub Flowの詳細”実践的なワークフロー
Section titled “実践的なワークフロー”機能開発の流れ:
# 1. mainブランチを最新化git checkout maingit pull origin main
# 2. featureブランチを作成git checkout -b feature/new-feature
# 3. 開発作業git add .git commit -m "新機能を実装"git push -u origin feature/new-feature
# 4. プルリクエストを作成(GitHubのWebインターフェース)# - タイトルと説明を記入# - レビュアーを指定# - ラベルを設定
# 5. CI/CDの実行を確認
# 6. レビューと承認
# 7. mainブランチにマージ(GitHubのWebインターフェース)
# 8. mainブランチを更新git checkout maingit pull origin main
# 9. featureブランチを削除git branch -d feature/new-featuregit push origin --delete feature/new-featureプルリクエストのベストプラクティス:
## プルリクエストのテンプレート
### 変更内容- ユーザー認証機能を実装- ログイン・ログアウト機能を追加
### 関連IssueCloses #123
### チェックリスト- [ ] コードレビューを依頼した- [ ] テストを追加した- [ ] ドキュメントを更新した- [ ] CIが成功しているGitLab Flowの詳細
Section titled “GitLab Flowの詳細”環境ごとのブランチ
Section titled “環境ごとのブランチ”ブランチ構成:
production (本番環境) └─ pre-production (ステージング環境) └─ main (開発環境) └─ feature/* (機能開発)実践的なワークフロー:
# 1. featureブランチで開発git checkout -b feature/new-feature main# 開発作業...git push -u origin feature/new-feature
# 2. mainブランチにマージ(プルリクエスト経由)
# 3. pre-productionブランチにマージ(ステージング環境へのデプロイ)git checkout pre-productiongit merge maingit push origin pre-production
# 4. ステージング環境でテスト
# 5. productionブランチにマージ(本番環境へのデプロイ)git checkout productiongit merge pre-productiongit push origin productionTrunk-based Developmentの詳細
Section titled “Trunk-based Developmentの詳細”実践的なワークフロー
Section titled “実践的なワークフロー”短命なブランチでの開発:
# 1. featureブランチを作成git checkout -b feature/small-change main
# 2. 迅速に開発(1-2日以内)git add .git commit -m "小さな変更"git push -u origin feature/small-change
# 3. すぐにプルリクエストを作成
# 4. レビューと承認
# 5. mainブランチにマージgit checkout maingit merge feature/small-changegit push origin main
# 6. featureブランチを削除git branch -d feature/small-changegit push origin --delete feature/small-change大規模な機能開発:
# 1. featureブランチを作成git checkout -b feature/large-feature main
# 2. 小さなコミットを頻繁に作成git add .git commit -m "機能の一部を実装"git push origin feature/large-feature
# 3. 定期的にmainブランチを取り込むgit checkout maingit pull origin maingit checkout feature/large-featuregit merge main # または rebase main
# 4. 完了したらプルリクエストを作成ブランチ戦略の詳細のポイント:
- Git Flow: 複数のブランチタイプ、明確な役割分担
- GitHub Flow: シンプルなワークフロー、プルリクエスト中心
- GitLab Flow: 環境ごとのブランチ、デプロイの制御
- Trunk-based Development: 短命なブランチ、迅速な開発
適切にブランチ戦略を実践することで、効率的で安全な開発ができます。