git worktree
git
書き方
git worktree add <path> [<branch>]同じリポジトリから二つ目の作業フォルダーを取り出し、クローンし直さずに二つのブランチを並行して扱えます。同じブランチを二か所にチェックアウトはできず、フォルダーを手で消すとpruneまで一覧に残ります。
よく使うオプション
| オプション | 意味 |
|---|---|
| add <path> <branch> | check that branch out into another folder |
| add -b <new> <path> | create a branch and check it out there |
| list | show every working tree of this repository |
| remove <path> | delete a working tree cleanly |
| prune | forget trees whose folder you deleted by hand |
| --detach | check out a commit without a branch |
例
git worktree add ../hotfix hotfix/logina second folder on another branch, sharing one .git
git worktree add -b release ../rel maincreates release from main in ../rel
git worktree remove ../hotfixremoves the folder and its bookkeeping entry
取り消しに何通りもあるのが混乱のもとです — ブランチの指す先を動かすのと、打ち消すコミットを積むのは別です。
読み方
- 角括弧 [ ] は省いてよい部分です。
- 三点 … は複数並べられるという意味です。
- オプションは大文字小文字を区別します — -r と -R が別物のコマンドもあります。
よくある質問
Q. git worktree は何をしますか。
同じリポジトリから二つ目の作業フォルダーを取り出し、クローンし直さずに二つのブランチを並行して扱えます。同じブランチを二か所にチェックアウトはできず、フォルダーを手で消すとpruneまで一覧に残ります。
Q. どう打ちますか。
git worktree add <path> [<branch>] — 角括弧は省いてよい部分です。
Q. よく使うオプションはいくつですか。
ここにまとめたのは6個です。全部は man git にあります。このコマンドはgitの仲間です。
関連するコマンド
man ページ: man git-worktree