# Git synthetic worktree

2 messages from 2025-08-12 to 2025-08-12. Participants: Jimmy Thrasibule, Antonio Russo.
Thread: https://gitlist.dev/t/63944

## Jimmy Thrasibule, 2025-08-12 07:56

Subject: Git synthetic worktree
Message-ID: <CAMqSRmCj-wcra=HE1=kv1LQU3UxhBg6zfbtO_OhWwJEqdf8gmw@mail.gmail.com>
URL: https://gitlist.dev/e/CAMqSRmCj-wcra%3DHE1%3Dkv1LQU3UxhBg6zfbtO_OhWwJEqdf8gmw%40mail.gmail.com

```
Hi,

I'd like to create a single worktree where files from multiple Git
repositories (or refs) coexist side-by-side (no subfolder separation),
but each with repository still independently tracked by Git.

There may be multiple uses cases such as vendoring where a child
project constructs a synthetic worktree with all its dependencies.
Another use case is to generate patches with a tool such as `Quilt
<https://savannah.nongnu.org/projects/quilt>` where the ``patches``
folder is an independent repository.

For example:

ˋˋˋ
PROJECT A
├ File A
├ File B
└ README
ˋˋˋ

ˋˋˋ
PROJECT B
├ patches
│ ├ File 1
│ └ File 2
└ README
ˋˋˋ

ˋˋˋ
SYNTHETIC
├ patches
│ ├ File 1
│ └ File 2
├ File A
├ File B
└ README
ˋˋˋ

To put it simply, I'd like to replicate `Overlay FS
<https://docs.kernel.org/filesystems/overlayfs.html>` in Git.

Now what happens when we have the same file in the repositories? We
can specify which repository is at the top of the stack.

The CLI experience could look like something like this:

ˋˋˋ
$ git clone repoA
$ git remote add repoB
$ git worktree push repoB/main
Usual git commands now applies to `repoB`.
$ git worktree top repoA.
Usual git commands now applies to `repoA`.
$ git worktree pop repoB/main
Files from `repoB` are gone.
ˋˋˋ

```

## Antonio Russo, 2025-08-12 13:40

Subject: Re: Git synthetic worktree
Message-ID: <b6179ded-abbf-4c9a-95c4-903451f7bc71@aerusso.net>
URL: https://gitlist.dev/e/b6179ded-abbf-4c9a-95c4-903451f7bc71%40aerusso.net
In-Reply-To: <CAMqSRmCj-wcra=HE1=kv1LQU3UxhBg6zfbtO_OhWwJEqdf8gmw@mail.gmail.com>

```
On 2025-08-12 01:56, Jimmy Thrasibule wrote:
> Hi,
> 
> I'd like to create a single worktree where files from multiple Git
> repositories (or refs) coexist side-by-side (no subfolder separation),
> but each with repository still independently tracked by Git.

I've accomplished something similar to this with a gitignore-everything
policy and sparse checkout (non-cone mode, very important!).

It's janky: I use GIT_DIR and GIT_WORK_TREE to force the selection of
which git repository, and I have to use 'git add -f' everywhere.

If you need something that works today, this may be a workaround.  It
does not allow for your "default override" based on layer priority,
instead it is very file-by-file specific.

As an aside, what you are describing sounds somewhat like a use-case
for ostree, which I know very little about.

Best,
Antonio

```
