ワークフロー
Git
Git Flow、タグ、サブモジュール
Git Flow
ブランチ戦略とコミットメッセージ規約
# ブランチの役割
# main — 本番リリース済みコード
# develop — 開発の統合ブランチ
# feature/* — 機能開発
# release/* — リリース準備
# hotfix/* — 本番バグ修正
# 機能開発フロー
git switch develop
git switch -c feature/user-auth
# ... 開発 ...
git switch develop
git merge --no-ff feature/user-auth
git branch -d feature/user-auth
# リリースフロー
git switch -c release/1.2.0 develop
# バージョン番号更新、最終テスト
git switch main
git merge --no-ff release/1.2.0
git tag -a v1.2.0 -m "Release v1.2.0"
git switch develop
git merge --no-ff release/1.2.0Conventional Commits
# 形式: <type>(<scope>): <subject>
# type: feat fix docs style refactor perf test chore
git commit -m "feat(auth): Googleログインを追加"
git commit -m "fix(api): 401エラーのハンドリングを修正"
git commit -m "docs(readme): インストール手順を更新"
git commit -m "refactor(db): クエリを最適化"
git commit -m "chore(deps): パッケージを更新"
git commit -m "test(auth): ログインテストを追加"
# Breaking Change
git commit -m "feat!: 認証APIを完全リデザイン"
# または本文に:
# BREAKING CHANGE: 旧APIとの互換性なし
# 複数行コミットメッセージ
git commit -m "feat(user): プロフィール画像のアップロードを追加
- AWS S3への直接アップロードを実装
- 画像のリサイズ処理を追加(最大2MB)
- アップロード失敗時のエラー処理を追加
Closes #123"上級コマンド
cherry-pick、bisect、submodule
# cherry-pick: 特定コミットだけ取り込む
git cherry-pick abc1234
git cherry-pick abc1234..def5678 # 範囲
git cherry-pick -n abc1234 # コミットせずにステージング
# bisect: バグが混入したコミットを二分探索
git bisect start
git bisect bad # 現在: バグあり
git bisect good v1.0.0 # v1.0.0: バグなし
# Gitが中間コミットをチェックアウト
git bisect good # または bad を繰り返す
git bisect reset # 完了後にHEADを戻す
# worktree: 複数ブランチを同時にチェックアウト
git worktree add ../hotfix hotfix/v1.1.1
git worktree list
git worktree remove ../hotfix
# clean: 追跡されていないファイルを削除
git clean -fd # ファイルとディレクトリを削除
git clean -fdn # ドライラン(実際には削除しない)
git clean -fdx # .gitignoreのファイルも削除
# submodule
git submodule add https://github.com/user/lib.git libs/lib
git submodule update --init --recursive
git submodule foreach git pull origin main