1

We have two projects A and B with shared library L. To avoid duplication of L' s history, we are considering to set up a Git monorepo which will contain A, B and L on the top-level:

/
+-- L
|   +-- src
|
+-- A
|   +-- .idea (project metadata)
|   +-- src
|
+-- B
    +-- .idea (project metadata)
    +-- src

A local checkout of project A or B should contain L as sub-directory, like:

A
+-- .idea (project metadata)
+-- src
+-- L
    +-- src

Is this possible with Git and sparse checkouts or any other Git functionality? If not, is there an alternative repository layout which does not duplicate L and still gives above working tree structure?

mstrap
  • 16,808
  • 10
  • 56
  • 86

1 Answers1

1

Is this possible with Git and sparse checkouts ...

Yes: the relatively new cone mode sparse checkout is designed for this structure. See How to use git sparse-checkout in 2.27+ which describes how what worked in Git 2.25 broke in Git 2.27, and what you should do instead.

Note that you'll probably want Git 2.27 or 2.28.

torek
  • 448,244
  • 59
  • 642
  • 775
  • Unfortunately what you are pointing to is not exactly what I'm looking for: we do not only need a sparse checkout of the existing repository structure, but also a slight rearrangement. In my example above, `L` which is actually a top-level repository directory should be moved below `A` in the local working tree. – mstrap Sep 23 '20 at 08:51
  • 1
    @mstrap: ah, I see. If you have symbolic links, making a symlink from A would be a workaround, but aside from that, no: there's no easy way to have Git arrange the work-tree differently from the names of the files as stored in the repository. You could perhaps do something sneaky with `git checkout-index --prefix`, but that will get messy. – torek Sep 23 '20 at 16:06