Skip to main content

GitHub Copilot Worktrees: Run Copilot in a Git Worktree

GitHub Copilot supports worktrees natively. Start Copilot CLI with copilot --worktree, switch an open session with /worktree, or pick New worktree when you start a session in the GitHub Copilot app or VS Code.

The Fix​

Copilot CLI, new session. Start the CLI inside a worktree with -w or --worktree:

copilot --worktree
copilot --worktree=fix-auth-tests

The name is optional. Without one, Copilot generates a branch name. The flag creates the worktree, or reuses it if it already exists, and starts the session inside it. It cannot be combined with --resume, --continue or --connect.

Copilot CLI, open session. Type one of these slash commands:

CommandWhat it does
/worktree [branch or task]Creates a worktree and switches to it. Uncommitted changes stay in the current worktree.
/move [branch or task]Moves your uncommitted changes into a new worktree and switches to it
/new worktreeStarts an empty session in a new worktree and leaves the current session where it is
/fork worktreeCopies the current conversation into a new session in a new worktree branched off HEAD

Pass a task description instead of a branch name, and Copilot uses it as the opening prompt in the new worktree. /worktree new still works but is deprecated in favor of /new worktree.

GitHub Copilot app. Click the plus icon next to Sessions, pick the repository, and in the Workspace dropdown choose New worktree and a base branch. Current checkout runs the session in your existing checkout instead.

VS Code. In the Agents window, choose New Worktree and a base branch when you start a session. Git worktrees in VS Code covers the editor's own worktree commands and cleanup.

Where Copilot CLI Puts Worktrees​

Copilot CLI creates worktrees under <repo>.worktrees/, next to your repository, unless you set worktreePathTemplate. A new worktree branches off your current HEAD. Set worktreeBaseRef to "defaultBranch" to branch off the remote default branch instead. Sessions started with --worktree resume in the same worktree after /restart.

A new worktree has tracked files only. Install dependencies and copy files like .env before the agent runs tests, as shown in Share node_modules across Git worktrees.

How Treq Handles It​

Treq starts GitHub Copilot CLI as one of its supported agents, in edit mode only. Each agent runs in its own Treq workspace, a separate working copy and branch under .treq/workspaces/, so you do not need --worktree there. treq agent start <branch> "<prompt>" -a copilot does the same from the CLI. Treq runs it as copilot --allow-all-tools, so read Agent Sessions for what that permits.

Sources​

Checked December 5, 2026: