github / github/copilot-cli

Copilot CLI uses global git stash in worktrees

Open
#1,725 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Shell
Stars
11.2k
Forks
1.9k
Avg merge
14h 16m
Merged PRs (30d)
6

Description

### Describe the bug

### Summary
When running multiple Copilot CLI agents in separate Git worktrees of the same repository, the agents use git stash under the hood. Because refs/stash is global to the repository, stashes created by one agent/worktree are visible to all others. As a result, another agent can inadvertently stash pop the wrong entry, causing cross‑worktree contamination (applying or dropping a different agent’s stash). This breaks the expected isolation of background sessions and can lead to data loss or corrupted workspace state. (Worktrees explicitly share refs and history; only HEAD and the index are per‑worktree.)

### Background / Rationale
In Git, all worktrees share the same repository object database and refs; only certain files are worktree‑local (e.g., HEAD, index). The stash lives at refs/stash, so the stash list is shared across worktrees. [[git-scm.com]](https://git-scm.com/docs/git-worktree), [[devtoolbox.dedyn.io]](https://devtoolbox.dedyn.io/blog/git-worktrees-complete-guide)
VS Code’s background‑agent guidance emphasizes using worktrees to isolate changes; however, using global stash inside those worktrees undermines that isolation when agents run in parallel. [code.visua...studio.com]

### Special Note
The mechanism used by GitHub Copilot CLI to resolve its stashing issues should not interfere with a user using git stash as it works out of the box/standard git stash management workflows.

### Affected version

GitHub Copilot CLI 0.0.419.

### Steps to reproduce the behavior

From a repo, create two worktrees A and B (e.g., git worktree add ../wt-A and git worktree add ../wt-B ). [git-scm.com]
Start Copilot CLI in both folders (A and B) and instruct each agent to make edits that trigger its internal use of git stash (e.g., when switching tasks/branches or preparing patches).
Agent in worktree A performs git stash (implicitly via Copilot).
Agent in worktree B later runs git stash pop (implicitly via Copilot).
Observe that B applies/drops A’s stash, not B’s own, because both sessions share the single refs/stash stack.

### Expected behavior

Each Copilot CLI session operating in a different worktree should have stash‑like isolation, so that temporary saves/restores of working changes cannot collide across worktrees.
Alternatively, Copilot CLI should avoid global stash entirely when multiple sessions might run concurrently within the same repository.

### Additional context

### Environment
Tool: GitHub Copilot CLI (latest at time of filing)
Context: Multiple concurrent Copilot CLI background sessions, each operating in its own git worktree directory for the same repo
Git: recent (worktrees enabled)
OS: reproducible on macOS and Linux (likely OS‑agnostic)

Contributor guide

Open the contributing guide

Research direction

The issue names no repository files, tests, or entry points. Reproduce the problem with two Git worktrees and concurrent Copilot CLI sessions, then trace the internal stash handling. Done means temporary changes remain isolated between worktrees without disrupting standard user-managed git stash workflows.

Written by the indexing model from the issue text.

Assessment

Tech stack
git
Domain
cli, developer-experience
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.