Git Worktree
適用 シナリオ:hotfix を処理 する必要 があるが、現在 の作業 を stash したくない場合 。
現在の位置を確認
git branch
# feature/l-001main から hotfix worktree を作成
git worktree add -b hotfix-123 .worktrees/hotfix-123 mainまたは:
git worktree add .worktrees/hotfix-123 maingit worktree list
/workspace/git-playground 0e439b8 [feature/l-001]
/workspace/git-playground/.worktrees/hotfix-123 0e439b8 [main]hotfix ディレクトリに切り替え
cd .worktrees/hotfix-1232番目 の方法 を使用 した場合 、追加 で checkout が必要 :
git checkout -b hotfix-123hotfix ブランチで問題を修正
# ファイルを修正
git add .
git commit -m "fix: issue description"hotfix をプッシュしてマージ
git push origin hotfix-123
# リモートで PR & Merge を完了プロジェクトルートに戻る
cd ../..hotfix worktree をクリーンアップ
git worktree remove .worktrees/hotfix-123
git fetch
git pull origin main元の feature ブランチの開発作業を継続
Demo
git worktree add ../worktree/feature/ABC-12345 prod.1.112.4 -b feature/ABC-12345