github / github/copilot-cli

Copilot CLI uses global git stash in worktrees

オープン
#1,725 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る
主要言語
Shell
スター
11.2k
フォーク
1.9k
平均マージ
14時間 16分
マージ済み PR(30日)
6

説明

### 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)

コントリビューションガイド

コントリビューションガイドを開く

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。