Home›GitHub Copilot›git worktreesとは?複数ブランチを同時にチェックアウトして並行開発を効率化する
What are git worktrees, and why should I use them?

git worktreesとは?複数ブランチを同時にチェックアウトして並行開発を効率化するWhat are git worktrees, and why should I use them?

元記事を読むRead original articlegithub.blog(新しいタブで開きます)(opens in a new tab)
AI2 点サマリSummary highlight
  • 2015年から存在するgit worktrees機能を解説。
  • 複数ブランチを異なるディレクトリで同時にチェックアウトでき、stashやブランチ切り替えなしで並行開発やホットフィックス対応を効率化できる仕組みと使い方を紹介する。

Explains git worktrees, available since 2015, which let you check out multiple branches in separate directories at once, streamlining parallel development and hotfixes without stashing or switching.

本ページの本文と要約は AI による自動生成です。日本語版と英語版は言語ごとに独立して生成されるため、表現や詳しさが異なる場合があります。正確性は元記事 (github.blog) をご確認ください。The body and summaries are AI-generated independently for each language, so wording and detail may differ. Verify accuracy at the original source (github.blog).

要約と収集メタデータに基づく AI 解説。元記事全文の転載・翻訳ではありません。AI explainer based on the summaries and collected metadata, not a copy or translation of the full source article.

Gitの「worktree(ワークツリー)」機能が、近年あらためて注目を集めている。2015年のGit 2.5で導入された比較的古い機能だが、複数のブランチを別々のディレクトリで同時にチェックアウトできる利点が、並行開発やAIエージェントの活用が広がるなかで再評価されている。

通常のGitリポジトリでは作業ディレクトリは一つだけで、ブランチを切り替えるにはgit switchやgit checkoutを使う。しかしこの方法では、編集中の変更をstashやコミットで退避しなければブランチを移れず、同時に複数の作業を進めるのは難しい。worktreesはこの制約を解消し、一つのリポジトリから複数の独立した作業ディレクトリを作り出せる。

使い方はシンプルで、git worktree addコマンドに新しいディレクトリのパスとブランチ名を指定すると、そのブランチをチェックアウトした別ディレクトリが生成される。git worktree listで一覧を確認でき、不要になればgit worktree removeで削除する。各ワークツリーは同じ.gitデータを共有するため、リポジトリ全体を別の場所へ完全に複製するよりディスク効率がよい点も特徴だ。

具体的な利用シーンとしては、機能開発の途中で緊急のホットフィックス対応が必要になった場合が挙げられる。従来は作業を中断して退避する必要があったが、worktreeを使えば別ディレクトリで修正ブランチを開き、本来の作業に影響を与えずに対応できる。テストの実行やプルリクエストのレビューを並行して進める用途にも向く。

近年の再評価には、GitHub CopilotをはじめとするAIコーディングエージェントの普及が関係していると見られる。複数のエージェントに別々のタスクを並行で割り当てる際、各エージェントが独立したディレクトリで作業すれば、変更が互いに干渉しにくくなるためだ。こうしたワークフローは他社のコーディング支援ツールでも広がりつつある。

一方で、ワークツリーが増えると管理が煩雑になりやすく、どのディレクトリがどのブランチに対応するかを把握しづらくなる可能性がある。チームで運用する場合は、命名規則や配置場所のルールを決めておくと混乱を避けやすい。Gitに標準搭載された機能のため追加インストールは不要で、まずは小規模な並行作業から試してみる価値があるだろう。

Git worktrees are one of the older features in Git's toolset, yet they have only recently moved into the spotlight. Introduced in 2015 with Git 2.5, worktrees let you check out multiple branches at the same time, each in its own directory, while still sharing a single underlying repository. For developers who routinely juggle several lines of work, this can remove a great deal of friction from everyday version control.

The core problem worktrees solve is the single-checkout limitation of a traditional Git working directory. Normally, a repository has one working tree, so switching between branches means running git checkout or git switch and overwriting the files in place. If you have uncommitted changes, you either commit prematurely or stash them, and any running build, test process, or development server tied to those files is disrupted. Worktrees sidestep this by allowing each branch to live in a separate folder on disk, so you can move between them simply by changing directories.

Creating a worktree is straightforward. From within an existing repository, running git worktree add ../feature-branch feature-branch creates a new directory containing a checkout of that branch. You can then open it in a separate editor window or terminal and work as if it were an independent clone. Behind the scenes, however, the worktrees share the same .git object database, so they remain lightweight compared with making full copies of the repository. Supporting commands include git worktree list to see all active worktrees, git worktree remove to delete one cleanly, and git worktree prune to tidy up references to directories that have been deleted manually.

The practical workflows this enables are easy to picture. A common example is the urgent hotfix. If you are deep into building a feature and a production bug needs immediate attention, you can spin up a new worktree based on the main branch, fix the issue there, and return to your feature work without ever stashing changes or losing your place. Another scenario is comparing two branches side by side, for instance to verify how a refactor behaves against the previous implementation, or to run two long test suites concurrently. Reviewers can also use a dedicated worktree to check out a colleague's pull request while keeping their own branch untouched.

Part of the renewed interest in worktrees appears to stem from the rise of AI coding agents and assistants such as GitHub Copilot. When an autonomous or semi-autonomous agent is asked to work on a task, it benefits from an isolated environment where it can edit files, run commands, and iterate without colliding with the developer's active session. Worktrees provide exactly that kind of isolation cheaply, which is likely why they are increasingly mentioned in the context of parallel and agent-driven development. Running several agents or experiments at once, each in its own worktree, lets a developer keep multiple streams of work progressing simultaneously.

It is worth understanding how worktrees relate to adjacent approaches. Before they became popular, developers often maintained multiple full clones of a repository to achieve a similar effect, but that wastes disk space and means fetches and remotes must be managed separately. Stashing remains useful for quick, temporary context switches, though it does not let you see two states at once. Worktrees sit between these options, offering true parallel checkouts without duplicating the entire object store.

There are some constraints to keep in mind. The same branch cannot be checked out in two worktrees at once, which prevents conflicting edits but occasionally requires planning. Worktrees stored outside the main project folder can be easy to forget, so periodic cleanup with prune and remove is advisable. Tooling, editor extensions, and continuous integration setups may also need configuration to recognize the separate directories.

For teams adopting Copilot or other AI-assisted workflows, worktrees pair naturally with feature branching, pull requests, and short-lived branches. They are not a replacement for those practices but a complement that reduces the cost of context switching. Anyone comfortable with basic Git commands can begin experimenting with a single git worktree add, and the feature's long presence in Git means it is stable, well documented, and available in any reasonably current installation.

ポコとTECHガイドPoko & TECH Guide

ポコと当サイトのTECHガイドが、記事の要約と収集した情報から読みどころを語るAI生成の対話です。Poko and TECH Dashboard's own TECH Guide discuss the article's highlights in an AI-generated conversation based on its summary and collected source details.

  1. ポコPokogit worktreesって何? 複数のブランチを同時に開けるって、つまりどういうこと?What are git worktrees? What does it mean to have multiple branches checked out at once?
  2. TECHガイドTECH Guide簡単に言うとじゃな、複数のブランチを別々のディレクトリへ同時にチェックアウトできるGitの機能じゃよ。記事によれば2015年からあるそうじゃ。Simply put, they’re a Git feature that checks out multiple branches into separate directories at the same time. According to the article, worktrees have been available since 2015.
  3. ポコPokoへえ! それって何がうれしいの? 普通にブランチを切り替えるのとは違う?Oh, neat! Why is that useful? How is it different from just switching branches?
  4. TECHガイドTECH Guide記事によれば、stashやブランチ切り替えをせずに並行開発やホットフィックス対応ができるんじゃ。作業を中断しにくいのがポイントじゃな。The article says you can handle parallel development or hotfixes without stashing work or switching branches. The key benefit is avoiding interruptions to your current task.
  5. ポコPokoつまり、ブランチごとに作業場所を分ければ、今の作業を保ったまま別の修正も進められるんだね!So each branch gets its own workspace, letting me keep my current work intact while tackling another fix!
  6. TECHガイドTECH Guideその理解でよいぞ。記事では仕組みだけでなく使い方も紹介しているので、並行作業を効率化したい人はそこが見どころじゃよ。Exactly. The article also covers how to use worktrees, so that’s the part to watch if you want to streamline parallel tasks.
記事情報・収集記録Article details & collection record
出典Source
GitHub Blog (AI & ML)公式Official
公開日時 (JST)Published (JST)
収集日時 (JST)Collected (JST)
配信形式Format
ブログBlog
原文言語Source language
EN
重要度の位置づけImportance in this lane
InfoInformational(GitHub Copilot 218件中、同等以上 218件)(218 of 218 GitHub Copilot entries are equal or higher)
出典の平均重要度(掲載直近 15 件・最大 30 件)Source average (last 15 listed, up to 30)
1.3 / 31=情報 · 2=中 · 3=高1=Info · 2=Medium · 3=High
情報の寿命Half-life
長期 (アーキテクチャ)Long-term (architecture)

🧠GitHub Copilot の他の記事More from GitHub Copilotもっと見る →View more →

ページ上部へScroll to top