2
0

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のメリットについて調べた

2
Last updated at Posted at 2025-12-14

昨今、AIとgit worktreeの相性が良いとSNSでよく散見するようになって、Worktreeのコマンド自体を知らなかったので、自分でも手を動かしながら調べてみました。

公式を見る限りだとgit worktreeが機能としてリリースされたのは2017年なのですね…。
なんで今まで話題にならなかったのだろう…?

git worktreeってどんなことしてくれる?

これに関しては色々な方が記事に書いてくれています。
中でもこの記事が分かりやすかったです。

今の作業ブランチはそのままの状態(他のブランチにswitchしない状態)で、別のブランチを「別の場所」で切って確認できるのが、git worktreeです。

AIと並走する以外での使用例

作業中にレビューが入り、一旦作業を中断する時に使えそうです。
例えばfeature/a-branchで作業している時にfeature/b-branchをレビューしなければいけなくなりました。
git worktreeを使わない場合だとgit stashで退避して、そこからfeature/b-branchにブランチを切り直し…ということをやっていたのですがgit worktreeだと以下のように行います。

$ git worktree add ../review origin/feature/b-branch

これでreviewディレクトリが作られます。

$ cd ../review

ここでreviewディレクトリに移動すると、feature/b-branchにswitchされている状態になっているという事です。

もし仮に開発環境のポート番号を3000番と3001番という感じに、意図的に変更できるのであればブラウザ上でBeforとAfterを確認することも可能のようです。

AIと並走する参考

2
0
0

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
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?