{"thread":{"id":"66941","subject":"[PATCH] worktree: allow sharing root files with linked worktrees","startedAt":"2026-11-26T18:25:17Z","lastAt":"2026-12-01T13:31:05Z","messageCount":5,"participants":["Bhushan Gaikwad via GitGitGadget","D. Ben Knoble","Bhushan Gaikwad","Eric Sunshine","Patrick Steinhardt"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"559481","messageId":"pull.2245.git.1795717517830.gitgitgadget@gmail.com","threadId":"66941","inReplyTo":null,"subject":"[PATCH] worktree: allow sharing root files with linked worktrees","fromName":"Bhushan Gaikwad via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2026-11-26T18:25:17Z","receivedAt":"2026-11-26T18:25:17Z","isPatch":true,"sender":{"key":"name:Bhushan Gaikwad","avatar":null},"body":"From: Bhushan Gaikwad <bhushan@alfredscholar.com>\n\nIgnored configuration files such as .env often need to remain identical\nacross linked worktrees. Today users must copy them manually or install a\npost-checkout hook, which is easy to forget and can create divergent local\nconfiguration.\n\nAdd a multi-valued worktree.sharedFile setting. For each configured\nroot-level regular file, worktree add creates an absolute symbolic link\nfrom the new worktree to the primary worktree before running the\npost-checkout hook.\n\nReject nested paths and source symlinks, avoid replacing checkout files,\nand fail cleanly when symbolic links are unavailable.\n\nSigned-off-by: Bhushan Gaikwad <bhushan@alfredscholar.com>\n---\n    worktree: allow sharing root files with linked worktrees\n\nPublished-As: https://github.com/gitgitgadget/git/releases/tag/pr-2245%2Fbhushan%2Fworktree-link-shared-files-v1\nFetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-2245/bhushan/worktree-link-shared-files-v1\nPull-Request: https://github.com/gitgitgadget/git/pull/2245\n\n Documentation/config/worktree.adoc | 13 ++++\n builtin/worktree.c                 | 78 ++++++++++++++++++++++++\n t/t2400-worktree-add.sh            | 95 ++++++++++++++++++++++++++++++\n 3 files changed, 186 insertions(+)\n\ndiff --git a/Documentation/config/worktree.adoc b/Documentation/config/worktree.adoc\nindex 0930183b91..ddd423caea 100644\n--- a/Documentation/config/worktree.adoc\n+++ b/Documentation/config/worktree.adoc\n@@ -18,3 +18,16 @@\n Note that setting `worktree.useRelativePaths` to \"`true`\" implies enabling the\n `extensions.relativeWorktrees` config (see linkgit:git-config[1]),\n thus making it incompatible with older versions of Git.\n+\n+`worktree.sharedFile`::\n+\tSpecify a file at the root of the primary worktree to create as a\n+\tsymbolic link in each new linked worktree. This is useful for ignored\n+\tconfiguration files which should be shared by all worktrees. Paths\n+\tcontaining directory separators are rejected. The variable may be\n+\tspecified more than once to share multiple files.\n++\n+The source must be a regular file, not a symbolic link. Missing or non-regular\n+sources are skipped with a warning. Git does not overwrite a path populated by\n+checkout, and warns instead. Shared files are linked before the `post-checkout`\n+hook runs. The symbolic link uses the absolute source path. Worktree creation\n+fails when symbolic links are disabled.\ndiff --git a/builtin/worktree.c b/builtin/worktree.c\nindex 77ecd0f71f..23af5f0beb 100644\n--- a/builtin/worktree.c\n+++ b/builtin/worktree.c\n@@ -131,6 +131,7 @@ static int verbose;\n static int guess_remote;\n static int use_relative_paths;\n static timestamp_t expire;\n+static struct string_list shared_files = STRING_LIST_INIT_DUP;\n \n static int git_worktree_config(const char *var, const char *value,\n \t\t\t       const struct config_context *ctx, void *cb)\n@@ -141,6 +142,14 @@ static int git_worktree_config(const char *var, const char *value,\n \t} else if (!strcmp(var, \"worktree.userelativepaths\")) {\n \t\tuse_relative_paths = git_config_bool(var, value);\n \t\treturn 0;\n+\t} else if (!strcmp(var, \"worktree.sharedfile\")) {\n+\t\tif (!value || is_absolute_path(value) ||\n+\t\t    strchr(value, '/') || strchr(value, '\\\\') ||\n+\t\t    !verify_path(value, S_IFREG))\n+\t\t\treturn error(_(\"invalid value for worktree.sharedFile: %s\"),\n+\t\t\t\t     value ? value : \"\");\n+\t\tstring_list_append(&shared_files, value);\n+\t\treturn 0;\n \t}\n \n \treturn git_default_config(var, value, ctx, cb);\n@@ -455,6 +464,73 @@ static void setup_alternate_ref_dir(struct worktree *wt, const char *wt_git_path\n \tstrbuf_release(&sb);\n }\n \n+static int link_shared_files(const char *path)\n+{\n+\tstruct worktree **worktrees;\n+\tstruct string_list_item *item;\n+\tstruct strbuf source = STRBUF_INIT;\n+\tstruct strbuf destination = STRBUF_INIT;\n+\tstruct strbuf primary = STRBUF_INIT;\n+\tstruct strbuf target = STRBUF_INIT;\n+\tint ret = 0;\n+\n+\tif (!shared_files.nr)\n+\t\treturn 0;\n+\tif (!repo_has_symlinks(the_repository))\n+\t\treturn error(_(\"worktree.sharedFile requires symbolic link support\"));\n+\n+\tworktrees = get_worktrees_without_reading_head(the_repository);\n+\tif (worktrees[0]->is_bare) {\n+\t\twarning(_(\"not linking shared files: primary worktree is bare\"));\n+\t\tgoto done;\n+\t}\n+\n+\tstrbuf_realpath(&primary, worktrees[0]->path, 1);\n+\tstrbuf_realpath(&target, path, 1);\n+\n+\tfor_each_string_list_item(item, &shared_files) {\n+\t\tstruct stat st;\n+\n+\t\tstrbuf_reset(&source);\n+\t\tstrbuf_addf(&source, \"%s/%s\", primary.buf, item->string);\n+\t\tif (lstat(source.buf, &st)) {\n+\t\t\twarning_errno(_(\"not linking shared file '%s'\"), source.buf);\n+\t\t\tcontinue;\n+\t\t}\n+\t\tif (!S_ISREG(st.st_mode)) {\n+\t\t\twarning(_(\"not linking shared file '%s': not a regular file\"),\n+\t\t\t\tsource.buf);\n+\t\t\tcontinue;\n+\t\t}\n+\n+\t\tstrbuf_reset(&destination);\n+\t\tstrbuf_addf(&destination, \"%s/%s\", target.buf, item->string);\n+\t\tif (!lstat(destination.buf, &st)) {\n+\t\t\twarning(_(\"not linking shared file '%s': destination already exists\"),\n+\t\t\t\titem->string);\n+\t\t\tcontinue;\n+\t\t} else if (errno != ENOENT) {\n+\t\t\tret = error_errno(_(\"could not inspect shared file destination '%s'\"),\n+\t\t\t\t\t  destination.buf);\n+\t\t\tgoto done;\n+\t\t}\n+\n+\t\tif (symlink(source.buf, destination.buf)) {\n+\t\t\tret = error_errno(_(\"could not link shared file '%s'\"),\n+\t\t\t\t\t  destination.buf);\n+\t\t\tgoto done;\n+\t\t}\n+\t}\n+\n+done:\n+\tfree_worktrees(worktrees);\n+\tstrbuf_release(&source);\n+\tstrbuf_release(&destination);\n+\tstrbuf_release(&primary);\n+\tstrbuf_release(&target);\n+\treturn ret;\n+}\n+\n static int add_worktree(const char *path, const char *refname,\n \t\t\tconst struct add_opts *opts)\n {\n@@ -591,6 +667,8 @@ static int add_worktree(const char *path, const char *refname,\n \tif (opts->checkout &&\n \t    (ret = checkout_worktree(opts, &child_env)))\n \t\tgoto done;\n+\tif ((ret = link_shared_files(path)))\n+\t\tgoto done;\n \n \tis_junk = 0;\n \tFREE_AND_NULL(junk_work_tree);\ndiff --git a/t/t2400-worktree-add.sh b/t/t2400-worktree-add.sh\nindex bdcca97633..0aa426bbac 100755\n--- a/t/t2400-worktree-add.sh\n+++ b/t/t2400-worktree-add.sh\n@@ -1288,4 +1288,99 @@ test_expect_success 'relative worktree sets extension config' '\n \ttest_cmp_config -C repo true extensions.relativeworktrees\n '\n \n+test_expect_success SYMLINKS 'worktree.sharedFile links files from the primary worktree' '\n+\ttest_when_finished \"git worktree remove --force shared-file-wt\" &&\n+\techo shared-secret >.env &&\n+\techo local-secret >.env.local &&\n+\ttest_config worktree.sharedFile .env &&\n+\tgit config --add worktree.sharedFile .env.local &&\n+\tgit worktree add --detach shared-file-wt &&\n+\ttest -L shared-file-wt/.env &&\n+\ttest -L shared-file-wt/.env.local &&\n+\ttest \"$(readlink shared-file-wt/.env)\" = \"$(pwd)/.env\" &&\n+\ttest_cmp .env shared-file-wt/.env &&\n+\ttest_cmp .env.local shared-file-wt/.env.local\n+'\n+\n+test_expect_success SYMLINKS 'worktree.sharedFile uses the primary worktree as source' '\n+\ttest_when_finished \"git worktree remove --force shared-source-wt\" &&\n+\ttest_when_finished \"git worktree remove --force existing-shared-source\" &&\n+\tgit worktree add --detach existing-shared-source &&\n+\techo primary >.env &&\n+\techo linked >existing-shared-source/.env &&\n+\ttest_config worktree.sharedFile .env &&\n+\tgit -C existing-shared-source worktree add --detach ../shared-source-wt &&\n+\techo primary >expect &&\n+\ttest_cmp expect shared-source-wt/.env\n+'\n+\n+test_expect_success SYMLINKS 'worktree.sharedFile is available to post-checkout hook' '\n+\ttest_when_finished \"git worktree remove --force shared-hook-wt\" &&\n+\ttest_when_finished \"rm -rf .git/hooks\" &&\n+\techo hook-secret >.env &&\n+\ttest_config worktree.sharedFile .env &&\n+\tmkdir .git/hooks &&\n+\ttest_hook post-checkout <<-\\EOF &&\n+\tcat .env >hook-env\n+\tEOF\n+\tgit worktree add --detach shared-hook-wt &&\n+\ttest_cmp .env shared-hook-wt/hook-env\n+'\n+\n+test_expect_success SYMLINKS 'worktree.sharedFile rejects paths outside primary worktree' '\n+\ttest_config worktree.sharedFile ../.env &&\n+\ttest_must_fail git worktree add --detach invalid-shared-file 2>err &&\n+\ttest_grep \"invalid value for worktree.sharedFile: ../.env\" err &&\n+\ttest_path_is_missing invalid-shared-file\n+'\n+\n+test_expect_success SYMLINKS 'worktree.sharedFile rejects nested paths' '\n+\ttest_config worktree.sharedFile nested/.env &&\n+\ttest_must_fail git worktree add --detach nested-shared-file 2>err &&\n+\ttest_grep \"invalid value for worktree.sharedFile: nested/.env\" err &&\n+\ttest_path_is_missing nested-shared-file\n+'\n+\n+test_expect_success SYMLINKS 'worktree.sharedFile does not follow source symlinks' '\n+\ttest_when_finished \"git worktree remove --force symlink-source-wt\" &&\n+\ttest_when_finished \"rm -f ../outside-shared-file shared-symlink\" &&\n+\techo outside >../outside-shared-file &&\n+\tln -s ../outside-shared-file shared-symlink &&\n+\ttest_config worktree.sharedFile shared-symlink &&\n+\tgit worktree add --detach symlink-source-wt 2>err &&\n+\ttest_grep \"not a regular file\" err &&\n+\ttest_path_is_missing symlink-source-wt/shared-symlink\n+'\n+\n+test_expect_success SYMLINKS 'worktree.sharedFile requires symlink support' '\n+\techo shared-secret >.env &&\n+\ttest_config worktree.sharedFile .env &&\n+\ttest_config core.symlinks false &&\n+\ttest_must_fail git worktree add --detach no-symlink-wt 2>err &&\n+\ttest_grep \"worktree.sharedFile requires symbolic link support\" err &&\n+\ttest_path_is_missing no-symlink-wt\n+'\n+\n+test_expect_success SYMLINKS 'worktree.sharedFile works with --no-checkout' '\n+\ttest_when_finished \"git worktree remove --force no-checkout-shared-wt\" &&\n+\techo shared-secret >.env &&\n+\ttest_config worktree.sharedFile .env &&\n+\tgit worktree add --detach --no-checkout no-checkout-shared-wt &&\n+\ttest -L no-checkout-shared-wt/.env &&\n+\ttest_cmp .env no-checkout-shared-wt/.env\n+'\n+\n+test_expect_success SYMLINKS 'worktree.sharedFile does not replace checkout files' '\n+\ttest_when_finished \"git worktree remove --force tracked-shared-file\" &&\n+\techo tracked >shared &&\n+\tgit add shared &&\n+\tgit commit -m shared-file &&\n+\techo primary-only >shared &&\n+\ttest_config worktree.sharedFile shared &&\n+\tgit worktree add --detach tracked-shared-file 2>err &&\n+\ttest_grep \"not linking shared file.*already exists\" err &&\n+\ttest_path_is_file tracked-shared-file/shared &&\n+\ttest ! -L tracked-shared-file/shared\n+'\n+\n test_done\n\nbase-commit: c46c1e37724f0478939de636ab8ea5a89086d532\n-- \ngitgitgadget\n\n"},{"id":"559711","messageId":"CALnO6CAX0hNzQ5t99wTwvbrruH5XCu3mbOAM6vdy4ZLMRHWdcg@mail.gmail.com","threadId":"66941","inReplyTo":"pull.2245.git.1795717517830.gitgitgadget@gmail.com","subject":"Re: [PATCH] worktree: allow sharing root files with linked worktrees","fromName":"D. Ben Knoble","fromEmail":"ben.knoble@gmail.com","sentAt":"2026-11-30T16:08:03Z","receivedAt":"2026-11-30T16:08:03Z","isPatch":true,"sender":{"key":"ben.knoble@gmail.com","avatar":"https://avatars.githubusercontent.com/u/22802209?v=4"},"body":"See also https://lore.kernel.org/git/CAA8YNQAsyUe275DLPRnB4dym5aq9ZyemA39u+HJciKzat5tNQA@mail.gmail.com/,\nperhaps?\n\nOn Thu, Nov 26, 2026 at 1:25 PM Bhushan Gaikwad via GitGitGadget\n<gitgitgadget@gmail.com> wrote:\n>\n> From: Bhushan Gaikwad <bhushan@alfredscholar.com>\n>\n> Ignored configuration files such as .env often need to remain identical\n> across linked worktrees. Today users must copy them manually or install a\n> post-checkout hook, which is easy to forget and can create divergent local\n> configuration.\n>\n> Add a multi-valued worktree.sharedFile setting. For each configured\n> root-level regular file, worktree add creates an absolute symbolic link\n> from the new worktree to the primary worktree before running the\n> post-checkout hook.\n>\n> Reject nested paths and source symlinks, avoid replacing checkout files,\n> and fail cleanly when symbolic links are unavailable.\n\nThe limitations and design choices seem odd to me:\n\n• On what platforms do we not support symlinks? Wikipedia suggests\nWindows has equivalents, but our mingw compatibility layer says they\nare disabled unless MSYS contains winsymlinks:nativestrict, and of\ncourse I don't know what other platforms do to customize the build.\n• Why reject nested paths? A project at work has api/.env{,.example}\nwhich might benefit.\n• Why use absolute symlinks? I suppose that might be annoying when a\ndirectory might have a different absolute path on different machines\n(due to NFS or something)? Is it a security thing, something about\nrelative symlinks becoming a nice target for some kind of exploit?\n\nI wonder if instead we could just copy the paths, which lets them\ndiverge (in case a worktree wants differing settings!), though at risk\nof forgetting the divergence in a long-lived worktree?\n\nI am somewhat negative on making Git do this automatically,\npersonally, especially since the example \".env\" is typically ignored\n(i.e., not managed by Git at all). But that's just my opinion, so if\nthe design is fleshed out and others are positive, ok.\n\n-- \nD. Ben Knoble\n\n"},{"id":"559756","messageId":"010601a22ff63cd4-ad6646b6-c34d-414e-ad82-1338e97b7d96-000000@ap-northeast-1.amazonses.com","threadId":"66941","inReplyTo":"CALnO6CAX0hNzQ5t99wTwvbrruH5XCu3mbOAM6vdy4ZLMRHWdcg@mail.gmail.com","subject":"Re: [PATCH] worktree: allow sharing root files with linked worktrees","fromName":"Bhushan Gaikwad","fromEmail":"bhushan@alfredscholar.com","sentAt":"2026-12-01T04:56:36Z","receivedAt":"2026-12-01T04:56:36Z","isPatch":true,"sender":{"key":"bhushan@alfredscholar.com","avatar":null},"body":"Hi Ben,\n\nThanks for looking at this, and for the pointer to the \"Branch\nAwareness\" thread. That thread is the same need from another angle:\npeople carry local, untracked config (settings.py, .env made from\n.env.example) next to tracked code. includeIf \"onbranch:\" solves the\nignore side, but nothing gets the file into a new worktree.\n\nD. Ben Knoble wrote:\n> On what platforms do we not support symlinks?\n\nplatform_has_symlinks() is true everywhere except the MinGW build,\nwhere it is true only with MSYS=winsymlinks:nativestrict. Separately,\nclone and init set core.symlinks=false on file systems that cannot\nstore links (FAT and similar). v1 handles this badly: with\nworktree.sharedFile set and no symlink support, the whole \"worktree\nadd\" fails and the new worktree is removed. That alone is a good\nreason to change the default.\n\n> Why reject nested paths?\n\nOnly to keep v1 small. With nested paths, a leading directory could\nbe a symlink (tracked or not) and send the file outside the worktree.\nThat is solvable: reject \"..\" and absolute paths, refuse a symlinked\nleading directory in the source and the destination, and create\nmissing leading directories. I plan to allow api/.env in v2.\n\n> Why use absolute symlinks?\n\nNo security reason. A relative link breaks when \"worktree move\"\nchanges the relative position of the two worktrees, and an absolute\nlink breaks when the primary worktree moves. Git already lets users\npick with worktree.useRelativePaths, so v2 should follow that setting\ninstead of hard-coding absolute links.\n\n> I wonder if instead we could just copy the paths\n\nI agree that copy is the better default. It works on every platform,\nand it lets a worktree keep its own settings. My plan for v2:\n\n  worktree.sharedFile      multi-valued path, nested paths allowed\n  worktree.sharedFileMode  \"copy\" (default) or \"symlink\"\n\nThe file is copied or linked after checkout and before the\npost-checkout hook. An existing path is never overwritten.\n\n> I am somewhat negative on making Git do this automatically\n\nFair. It is opt-in: nothing happens unless a user sets the key, and it\nis local config, so it is never forced on anyone through the repo.\nThe alternative today is a post-checkout hook that every user writes\nagain, which has to work out where the primary worktree is and must\nskip normal branch switches. If the list prefers that route, I am\nhappy to document a hook recipe in git-worktree(1) instead.\n\nBefore I send v2, does copy-by-default with an opt-in symlink mode\naddress your concerns? I would also welcome other opinions on the\nconfig names.\n\nThanks,\nBhushan\n\n"},{"id":"559757","messageId":"CAPig+cSLCcMzQGZggOBDnwjveKBqKuhNr5c=HFbnbvox1Fm0oA@mail.gmail.com","threadId":"66941","inReplyTo":"CALnO6CAX0hNzQ5t99wTwvbrruH5XCu3mbOAM6vdy4ZLMRHWdcg@mail.gmail.com","subject":"Re: [PATCH] worktree: allow sharing root files with linked worktrees","fromName":"Eric Sunshine","fromEmail":"ericsunshine@gmail.com","sentAt":"2026-12-01T05:31:20Z","receivedAt":"2026-12-01T05:31:20Z","isPatch":true,"sender":{"key":"ericsunshine@gmail.com","avatar":null},"body":"On Mon, Nov 30, 2026 at 11:08 AM D. Ben Knoble <ben.knoble@gmail.com> wrote:\n> On Thu, Nov 26, 2026 at 1:25 PM Bhushan Gaikwad via GitGitGadget\n> <gitgitgadget@gmail.com> wrote:\n> > Ignored configuration files such as .env often need to remain identical\n> > across linked worktrees. Today users must copy them manually or install a\n> > post-checkout hook, which is easy to forget and can create divergent local\n> > configuration.\n> >\n> > Add a multi-valued worktree.sharedFile setting. For each configured\n> > root-level regular file, worktree add creates an absolute symbolic link\n> > from the new worktree to the primary worktree before running the\n> > post-checkout hook.\n> >\n> > Reject nested paths and source symlinks, avoid replacing checkout files,\n> > and fail cleanly when symbolic links are unavailable.\n>\n> The limitations and design choices seem odd to me:\n>\n> • On what platforms do we not support symlinks? Wikipedia suggests\n> Windows has equivalents, but our mingw compatibility layer says they\n> are disabled unless MSYS contains winsymlinks:nativestrict, and of\n> course I don't know what other platforms do to customize the build.\n> • Why reject nested paths? A project at work has api/.env{,.example}\n> which might benefit.\n> • Why use absolute symlinks? I suppose that might be annoying when a\n> directory might have a different absolute path on different machines\n> (due to NFS or something)? Is it a security thing, something about\n> relative symlinks becoming a nice target for some kind of exploit?\n\nFor what it's worth, these are the exact same questions/oddities which\ncame to my mind upon reading the commit message.\n\n> I am somewhat negative on making Git do this automatically,\n> personally, especially since the example \".env\" is typically ignored\n> (i.e., not managed by Git at all). But that's just my opinion, so if\n> the design is fleshed out and others are positive, ok.\n\nI am similarly negative on this proposal. While I understand that it\naddresses a real need, I can't help but feel that it is too\nspecialized and narrowly focused. It feels quite out of place for the\notherwise generic worktree mechanism. I could imagine having a more\nfavorable reaction to a proposal for a more generally applicable\nsolution, however, a very general mechanism already exists in the form\nof hooks. (And, yes, I am aware that the commit message mentions the\npotential downside of employing a hook for this case.)\n\nBhushan's alternative proposal[*] of instead documenting a hook recipe\nin git-worktree(1), on the other hand, seems reasonable. Adding a\nsample hook to .git/hooks/ might be even better.\n\n[*]: https://lore.kernel.org/git/010601a22ff63cd4-ad6646b6-c34d-414e-ad82-1338e97b7d96-000000@ap-northeast-1.amazonses.com/\n\n"},{"id":"559792","messageId":"aw7MGWp_O6cPhFty@pks.im","threadId":"66941","inReplyTo":"CAPig+cSLCcMzQGZggOBDnwjveKBqKuhNr5c=HFbnbvox1Fm0oA@mail.gmail.com","subject":"Re: [PATCH] worktree: allow sharing root files with linked worktrees","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-12-01T13:31:05Z","receivedAt":"2026-12-01T13:31:05Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"On Tue, Dec 01, 2026 at 12:31:20AM -0500, Eric Sunshine wrote:\n> On Mon, Nov 30, 2026 at 11:08 AM D. Ben Knoble <ben.knoble@gmail.com> wrote:\n> > On Thu, Nov 26, 2026 at 1:25 PM Bhushan Gaikwad via GitGitGadget\n> > <gitgitgadget@gmail.com> wrote:\n> > > Ignored configuration files such as .env often need to remain identical\n> > > across linked worktrees. Today users must copy them manually or install a\n> > > post-checkout hook, which is easy to forget and can create divergent local\n> > > configuration.\n> > >\n> > > Add a multi-valued worktree.sharedFile setting. For each configured\n> > > root-level regular file, worktree add creates an absolute symbolic link\n> > > from the new worktree to the primary worktree before running the\n> > > post-checkout hook.\n> > >\n> > > Reject nested paths and source symlinks, avoid replacing checkout files,\n> > > and fail cleanly when symbolic links are unavailable.\n> >\n> > The limitations and design choices seem odd to me:\n> >\n> > • On what platforms do we not support symlinks? Wikipedia suggests\n> > Windows has equivalents, but our mingw compatibility layer says they\n> > are disabled unless MSYS contains winsymlinks:nativestrict, and of\n> > course I don't know what other platforms do to customize the build.\n> > • Why reject nested paths? A project at work has api/.env{,.example}\n> > which might benefit.\n> > • Why use absolute symlinks? I suppose that might be annoying when a\n> > directory might have a different absolute path on different machines\n> > (due to NFS or something)? Is it a security thing, something about\n> > relative symlinks becoming a nice target for some kind of exploit?\n> \n> For what it's worth, these are the exact same questions/oddities which\n> came to my mind upon reading the commit message.\n> \n> > I am somewhat negative on making Git do this automatically,\n> > personally, especially since the example \".env\" is typically ignored\n> > (i.e., not managed by Git at all). But that's just my opinion, so if\n> > the design is fleshed out and others are positive, ok.\n> \n> I am similarly negative on this proposal. While I understand that it\n> addresses a real need, I can't help but feel that it is too\n> specialized and narrowly focused. It feels quite out of place for the\n> otherwise generic worktree mechanism. I could imagine having a more\n> favorable reaction to a proposal for a more generally applicable\n> solution, however, a very general mechanism already exists in the form\n> of hooks. (And, yes, I am aware that the commit message mentions the\n> potential downside of employing a hook for this case.)\n> \n> Bhushan's alternative proposal[*] of instead documenting a hook recipe\n> in git-worktree(1), on the other hand, seems reasonable. Adding a\n> sample hook to .git/hooks/ might be even better.\n> \n> [*]: https://lore.kernel.org/git/010601a22ff63cd4-ad6646b6-c34d-414e-ad82-1338e97b7d96-000000@ap-northeast-1.amazonses.com/\n\nSorry for repeating what you're saying, but my immediate reaction was\nalso that this is way too niche of a use case, and that adding a hook\nwould be the better solution to this.\n\nBut the other question is whether you really need a hook in order to\nachieve this. In other words, isn't it sufficient to have a small script\nthat wraps git-worktree(1) to create the worktree and copy over the\nfiles? We typically only add hooks when there really is no other way to\nachieve something, e.g. when it happens in the middle of an operation\nperformed by Git. But that's not really the case here, as it can be\ntrivially achieved by such a small wrapper script.\n\nThanks!\n\nPatrick\n\n"}]}