Skip to content

submodule: support worktree-specific configuration - #2306

Open
yoichi wants to merge 4 commits into
gitgitgadget:masterfrom
yoichi:submodule-with-worktree
Open

yoichi wants to merge 4 commits into
gitgitgadget:masterfrom
yoichi:submodule-with-worktree

Conversation

@yoichi

@yoichi yoichi commented Nov 9, 2026

Copy link
Copy Markdown

When extensions.worktreeConfig is enabled, this series stores submodule settings that can differ between worktrees in the worktree config.

It also handles submodule..gitdir specially, since this setting must not be shared between worktrees.

The changes include:

  • Store submodule settings in the worktree config when extensions.worktreeConfig is enabled.
  • Keep submodule..gitdir relative for linked worktrees and exclude it when copying configuration to a new worktree.
  • Enable worktree config when migrating existing gitdir settings.
  • Make git submodule init copy an existing gitdir setting to the current worktree config only when it belongs to that worktree.

@yoichi
yoichi force-pushed the submodule-with-worktree branch 3 times, most recently from 8e0008f to b4eda07 Compare November 10, 2026 14:01
For a linked worktree, always keep `submodule.<name>.gitdir` relative
to ensure it continues to work when the worktree is moved along with
the main worktree. (This benefit also requires
worktree.useRelativePaths to be set to true.)

Signed-off-by: Yoichi NAKAYAMA <yoichi.nakayama@gmail.com>
Submodule settings such as `submodule.<name>.active` and
`submodule.<name>.url` can differ between worktrees, so store them in
the worktree config when extensions.worktreeConfig is enabled.

Settings shared between worktrees can remain in the repository
config. When such a setting exists there, 'git submodule deinit' sets
`submodule.<name>.active` to false in the worktree config to
unregister the submodule.

Unlike other settings, `submodule.<name>.gitdir` should not be shared
between worktrees, so exclude it from the config copied by 'git
worktree add'.

Signed-off-by: Yoichi NAKAYAMA <yoichi.nakayama@gmail.com>
When a repository has multiple worktrees, the submodule gitdir
locations for each worktree must be stored separately. When 'git
submodule--helper migrate-gitdir-configs' runs, it enables
extensions.worktreeConfig and stores each gitdir setting in the
corresponding worktree's config.

Signed-off-by: Yoichi NAKAYAMA <yoichi.nakayama@gmail.com>
If a repository already has gitdir settings in its repository config
when extensions.worktreeConfig is enabled, those settings belong to a
particular worktree. Make 'git submodule init' copy an existing
setting to the worktree config if it belongs to the current worktree;
otherwise, generate a new setting.

Signed-off-by: Yoichi NAKAYAMA <yoichi.nakayama@gmail.com>
@yoichi
yoichi force-pushed the submodule-with-worktree branch from b4eda07 to 68bbdbb Compare November 11, 2026 20:51
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.

1 participant