Local config is not shared across git worktrees
Problem
Local config (glab config set without --global) is stored per worktree. LocalConfigDir in internal/config/local_config.go uses git rev-parse --git-dir, so a linked worktree reads and writes .git/worktrees/<name>/glab-cli/config.yml rather than the shared .git/glab-cli/config.yml.
As a result, config set in the main checkout is silently ignored in every linked worktree. Each new worktree starts with no local config and falls back to global. This hits tools that create short-lived worktrees often (for example, AI coding agents) especially hard.
Steps to reproduce
glab config set editor main-only-editor # in the main checkout
git worktree add ../wt main --detach
cd ../wt && glab config get editor # prints nothingTested on v1.120.0 (d4053d449).
Why share it
- Git shares
.git/configacross all worktrees. Per-worktree config is opt-in (extensions.worktreeConfig,git config --worktree). glab currently does the reverse. - Local config keys describe the repository (host, remote, editor, browser,
check_update), not a branch. Nothing in them depends on the checkout. - Stacks were changed to be shared across worktrees in #8355 (closed) (
0a119c022) for the same reason.
The per-worktree location comes from #7872 (closed), where separate worktree config was described as preferable. This issue proposes keeping that as an opt-in override rather than the default.
Proposal
- Read local config in this order: the per-worktree file (
.git/worktrees/<name>/glab-cli/config.yml) if it exists, then the shared file ($(git rev-parse --git-common-dir)/glab-cli/config.yml), then global. Existing per-worktree files keep working. - Write to the shared file by default. Optionally add
glab config set --worktreefor per-worktree overrides, mirroringgit config --worktree. - Normal checkouts are unaffected, because
--git-dirand--git-common-dirresolve to the same directory. Submodules keep their own config, because their common dir is.git/modules/<name>.
Related
The local config file in a normal checkout also collects duo_cli_binary_* and orbit_local_* keys. These look like machine-wide binary state that belongs in global config or a cache, not repo-local config. It's probably worth tracking separately.