From: Jimmy Aguilar Mena <kratsbinovish@gmail.com>
To: phillip.wood123@gmail.com
Cc: git@vger.kernel.org, phillip.wood@dunelm.org.uk,
kratsbinovish@gmail.com
Subject: Re: [RFC] worktree: add --recurse-submodules support to git worktree add
Date: Wed, 15 Apr 2026 17:12:48 +0200 [thread overview]
Message-ID: <ad-pAL9wDZ-KDfcn@RTX> (raw)
Phillip,
Good catch — let me clarify what the script actually places on disk.
The hardlink copy does not go into $GIT_COMMON_DIR/modules/ (which
both worktrees would then share). It goes into each worktree's own
gitdir entry:
cp -al $GIT_COMMON_DIR/modules \
$GIT_COMMON_DIR/worktrees/$id/modules
So worktree A uses $GIT_COMMON_DIR/modules/sub/ and worktree B uses
$GIT_COMMON_DIR/worktrees/B/modules/sub/ — these are physically
separate directory trees with separate paths.
Within those trees the files start out as hardlinks (same inode), but
that only affects disk space accounting. It does not mean the data is
shared. Git writes files atomically by writing to a lock file and then
calling rename(2), which gives the path a new inode. So the first time
git touches HEAD, index, or any ref in one worktree's submodule
gitdir, the rename breaks that hardlink and the file becomes
independent. The other worktree's copy is untouched.
The only files that stay hardlinked forever are pack files and loose
object files — precisely because git objects are immutable by
design. Two pack files with the same content should share the same
disk blocks; there is no correctness issue.
The net effect is the same separation git worktree already provides
for the outer repo (HEAD and index under
$GIT_COMMON_DIR/worktrees/$id/, objects shared under
$GIT_COMMON_DIR/objects/), but achieved through the filesystem rather
than explicit gitdir configuration. A native --recurse-submodules
implementation should do the same thing explicitly — probably by
running the equivalent of git -C <sub-gitdir> worktree add for each
submodule, which would give each submodule its own proper worktrees/
structure rather than relying on the hardlink + rename behaviour.
Signed-off-by: Jimmy Aguilar Mena kratsbinovish@gmail.com
next reply other threads:[~2026-04-15 15:12 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-15 15:12 Jimmy Aguilar Mena [this message]
-- strict thread matches above, loose matches on Subject: below --
2026-04-15 0:14 [RFC] worktree: add --recurse-submodules support to git worktree add JAM
2026-04-15 14:05 ` Phillip Wood
2026-04-15 16:23 ` Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ad-pAL9wDZ-KDfcn@RTX \
--to=kratsbinovish@gmail.com \
--cc=823d30b3-b355-430b-b8af-c8421a87b0aa@gmail.com \
--cc=git@vger.kernel.org \
--cc=phillip.wood123@gmail.com \
--cc=phillip.wood@dunelm.org.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox