GitWorktree.org logoGitWorktree.org

GitHub Copilot with Git Worktree

GitHub Copilot provides AI-powered code completion and chat inside your editor, plus a CLI tool for terminal-based assistance. Both work inside git worktree directories with minimal configuration. This guide covers how Copilot interacts with worktrees and how to get the best experience across multiple worktree directories.

Does Copilot Support Worktrees?

Yes. GitHub Copilot works in any directory that is part of a git repository, including worktree directories. When you open a worktree in VS Code or another supported editor, Copilot detects the git context automatically and provides completions based on the files in that worktree.

Copilot does not need to know that a directory is a worktree rather than a regular clone. From Copilot's perspective, it is working with a normal project directory that happens to have a .git file (instead of a .git directory) pointing to the main repository. This distinction is transparent to Copilot and to your editor.

The one caveat: Copilot's context window includes files from the currently open workspace. If you have multiple worktrees open in separate editor windows, each Copilot instance builds context from its own workspace's files, which is exactly the behavior you want for isolated development.

Using Copilot in Worktree Directories

The setup is the same as using Copilot in any project: open the worktree directory in your editor and start coding. Copilot provides completions based on the files and branch in that worktree.

Open a worktree with Copilot
# Create a worktree for your feature
git worktree add ../my-project-feat-search -b feat/search

# Open it in VS Code (Copilot activates automatically)
code ../my-project-feat-search

# Or open in another editor window alongside your main checkout
# Each window gets its own Copilot context

When using Copilot Chat in a worktree, the chat context includes files from the worktree's branch. If your feature branch has new files that do not exist on main, Copilot Chat can reference them. If the main branch has files not in your worktree (because you deleted them in your feature branch), Copilot will not suggest them.

This branch-aware context is one of the advantages of using worktrees with Copilot: each editor window provides Copilot with the right context for its task.

Copilot CLI and Worktrees

GitHub Copilot in the CLI (gh copilot) works in any directory, including worktrees. You can use it to explain commands, suggest fixes, or generate shell scripts, all within the context of a specific worktree:

Copilot CLI in a worktree
# Navigate to a worktree
cd ../my-project-feat-search

# Use Copilot CLI for suggestions
gh copilot suggest "write a test for the search function"

# Explain a git command
gh copilot explain "git worktree list --porcelain"

# Get help with a command
gh copilot suggest "find all files changed between this branch and main"

Copilot CLI uses your current directory as context for its suggestions. When you run it inside a worktree, it picks up the files and git state of that worktree, giving you relevant suggestions for the task at hand.

Workspace Configuration

When using multiple worktrees with Copilot, workspace settings ensure a consistent experience across all worktrees:

Shared Settings via Git

Settings stored in .vscode/settings.json are tracked by git and automatically available in every worktree. This is the best place to configure Copilot workspace-level settings:

.vscode/settings.json
{
  "github.copilot.enable": {
    "*": true,
    "markdown": true,
    "plaintext": false
  },
  "github.copilot.advanced": {
    "length": 500
  }
}

Per-Worktree Overrides

If you need different Copilot settings in a specific worktree (for example, disabling Copilot for a security-sensitive branch), you can override the workspace settings by creating or modifying the .vscode/settings.jsonin that worktree's branch. Since each worktree has its own branch, those changes stay isolated.

Multi-Root Workspaces

You can open multiple worktrees in a single VS Code window as a multi-root workspace. This lets Copilot see files from all worktrees in its context, which can be useful for cross-referencing but may also introduce noise:

my-project.code-workspace
{
  "folders": [
    { "path": "../my-project-main" },
    { "path": "../my-project-feat-search" },
    { "path": "../my-project-fix-auth" }
  ],
  "settings": {
    "github.copilot.enable": {
      "*": true
    }
  }
}

For most workflows, separate windows per worktree give cleaner Copilot suggestions because the context is focused on one task.

Tips

Copilot Learns from Open Files

Copilot uses the files currently open in your editor as context. In a worktree, open the files most relevant to your task so Copilot gives better suggestions. If you are working on a search feature, keep the search-related files open.

Authentication Works Across Worktrees

Copilot authentication is tied to your GitHub account and editor, not to the project directory. You do not need to re-authenticate when opening a new worktree. Your subscription and settings carry over automatically.

Combine with Other AI Tools

Copilot complements other AI coding tools well. You can use Copilot for inline completions in your main checkout while running Claude Code or Cursor agents in separate worktrees for larger tasks.

Copilot Chat in Worktree Context

When using Copilot Chat, reference files using the #filesyntax. In a worktree, this references the worktree's version of the file, not the main branch's version, which keeps the chat focused on your current task.

Summary

GitHub Copilot works seamlessly in git worktree directories with no additional configuration required. Each worktree window gives Copilot focused context for that branch's task, and workspace settings are shared via git. For parallel agent workflows that go beyond inline completions, combine Copilot with tools like Claude Code or check the parallel agents guide for multi-agent setups.