Repository navigation
Description
Describe the bug
When gh repo sync updates a non-current local branch, it checks for associated worktrees only after trying to update the branch. On Git 2.34.1, that update can succeed even if the branch is checked out in another worktree. Sync then reports success and the other worktree can be left with stale files and index state.
Affected version
gh version 2.104.0-50-ge1219499a (2026-11-18)
Steps to reproduce the behavior
- Type this:
go test ./... - These tests will fail:
- TestExecuteLocalRepoSyncNonCurrentBranch/branch_checked_out_in_another_worktree
- TestExecuteLocalRepoSyncNonCurrentBranch/branch_associated_with_prunable_worktree
Expected vs actual behavior
Expected behavior
When the target branch is checked out in another worktree, gh sync repo should refuse to update it and explain how to sync safely.
Before updating the ref, gh repo sync should detect whether the branch is checked out in another worktree (including stale/prunable worktree metadata), refuse to update it and show an actionable message. Syncing a branch not associated with another worktree should continue to work.
Actual behavior
gh sync repo can report success and move the target even though it is checked out in another worktree. that worktree's files and index remain at the old commit, leaving them out of sync with the branch.
Logs
--- FAIL: TestExecuteLocalRepoSyncNonCurrentBranch (0.65s)
--- FAIL: TestExecuteLocalRepoSyncNonCurrentBranch/branch_checked_out_in_another_worktree (0.18s)
sync_test.go:143:
Error Trace: github-cli/pkg/cmd/repo/sync/sync_test.go:143
Error: An error is expected but got nil.
Test: TestExecuteLocalRepoSyncNonCurrentBranch/branch_checked_out_in_another_worktree
--- FAIL: TestExecuteLocalRepoSyncNonCurrentBranch/branch_associated_with_prunable_worktree (0.13s)
sync_test.go:169:
Error Trace: github-cli/pkg/cmd/repo/sync/sync_test.go:169
Error: An error is expected but got nil.
Test: TestExecuteLocalRepoSyncNonCurrentBranch/branch_associated_with_prunable_worktree
FAIL
Activity
cli-triage commentedon Nov 21, 2026
I believe this is a duplicate of #12927 because it tracks the same
gh repo syncfailure where advancing a branch checked out in another worktree leaves that worktree's index and files stale.Generated by issue triage.
brechtcox-be commentedon Nov 21, 2026
This is marked as a duplicate. However the issue that is being referred to #12927 as duplicate is closed although the bug is still happening.
I have a fix for this and can open a PR for it but the issue should first be labeled
help wanted.sergiou87 commentedon Nov 23, 2026
According to Copilot…
brechtcox-be commentedon Nov 23, 2026
I'm willing to open a PR for a solution but I'm not allowed to without this issue having the
help wantedlabel.