Skip to content

Fix git-crypt in linked worktrees (shared key via --git-common-dir)#334

Open
thebino wants to merge 1 commit into
AGWA:masterfrom
thebino:fix/worktree-keys-common-dir
Open

Fix git-crypt in linked worktrees (shared key via --git-common-dir)#334
thebino wants to merge 1 commit into
AGWA:masterfrom
thebino:fix/worktree-keys-common-dir

Conversation

@thebino

@thebino thebino commented Jul 1, 2026

Copy link
Copy Markdown

Running git worktree add inside a git-crypt repository fails in the smudge filter:

git-crypt: Error: Unable to open key file - have you unlocked/initialized this repository yet?
error: external filter '"git-crypt" smudge' failed
fatal: <file>: smudge filter git-crypt failed

git-crypt resolves its internal state directory (.git/git-crypt, which holds the symmetric keys) from git rev-parse --git-dir. In a linked worktree that returns .git/worktrees/<name>, which never contains the keys — they only ever live in the shared common dir. So checkout of an encrypted file in the new worktree aborts.


This PR resolves the state directory via git rev-parse --git-common-dir instead.
In the main worktree this is identical to --git-dir, so behaviour there is unchanged.
In a linked worktree it points at the shared git directory where the keys live, so checkout, lock and unlock all work transparently.


This is the minimal, shared-key approach. See companion #333 for a variant that preserves per-worktree lock state via a fallback. They touch the same function and are mutually exclusive — pick whichever fits.

Fixes #105

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

git worktree add in repo with encrypted commited file made encrypted fails.

1 participant