0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Git worktree ってのが便利って聞きました

Posted at

image.png

はじめに

先日、チームメンバーの方から git worktree が便利って話を聞きました。私は使った事が無いコマンドだったので、まずは使ってみました!

git worktree

git worktree を使うと、一つのローカルリポジトリで作業ツリーを複数同時に持てる。
ざっくり言うと、作業ディレクトリ内にさらに作業ディレクトリを作って、git checkoutしてくれます。
元の作業ディレクトリはそのままっての良い!
追加した作業ディレクトリに cd コマンドで移動して、いつものGitのように使える。

<イメージ>

作業ディレクトリ(feature/b)
 ┣ a.txt
 ┣ b.txt
 ┗ README.md
> git worktree add worktree_a feature/a
作業ディレクトリ(feature/b)
 ┣ a.txt
 ┣ b.txt
 ┣ README.md
 ┗ worktree_a
   ┣ a.txt
   ┗ README.md

※詳細は、下記の「参考」をご覧ください。

コマンド

worktree追加

> git worktree add [作成ディレクトリ名] [checkoutブランチ名]

忘れないように"作成ディレクトリ名"は、"worktree_ブランチ名"にする

worktree一覧

> git worktree list

元の作業ディレクトリも含めて一覧で表示される

例:

> git worktree list
[パス]/test_project             e0903c4 [feature/b]
[パス]/test_project/worktree_a  315c4c2 [featue/a]

worktee削除

> git worktree remove [作成ディレクトリ名]

作成したディレクトリごと削除される

git worktree prune コマンドで、作成したすべての worktree が削除されるはずですが、私の環境では削除してくれませんでした。。。

※バージョン:git version 2.46.0.windows.1

おわりに

試してみて、確かに使えるコマンドだという事が分かりました!
良くある、”ちょっと確認してみて”って時に、git stashとかいろいろしてた手数が減りますね。


参考(感謝)

0
1
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?