0

I want to have an umbrella repo (monorepo) with multiple projects in such a way that I should be able to clone each project individually, modify and push without having to clone the whole monorepo.

monorepo                                                                                           
  |                                     
  --- project1_repo                                       
  |                                         
  --- project2_repo                                
  |                        
  --- project3_repo

E.g. I should be able to clone project2_repo, modify it and then git push without having to clone the whole monorepo with all projects.

What would be the best approach? Is git submodule the only way for this?

LeGEC
  • 46,477
  • 5
  • 57
  • 104
yk28
  • 25
  • 1
  • 1
  • 7
  • 1
    Git cannot easily [clone/fetch/pull](https://stackoverflow.com/search?q=%5Bgit%5D+clone+subdirectory) a subdirectory, it can only fetch full commits or chains of commits. Submodules is not the only way to work around the limitation but it's the most elaborated. IMO if you use submodules the superproject is no longer a monorepo. – phd Feb 09 '23 at 06:42
  • 1
    So you want a monorepo but also don't want a monorepo? What does "monorepo" even mean if you can check out and build individual parts separately? Personally I've never had good experiences with git-based monorepos. I'm sure some mange it, but it's always been a pain for me. – Joachim Sauer Feb 09 '23 at 09:52

2 Answers2

1

I should be able to clone project2_repo, modify it and then git push without having to clone the whole monorepo with all projects.

If you are not using submodules or subtrees, you can still work with only one repository by doing a git sparse-checkout as explained in "Get up to speed with partial clone and shallow clone"

That way, you can work on the part of the monorepo you need, without cloning everything.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
1

I have been working on solving this exact problem for a few years now: https://github.com/josh-project/josh

It does require some setup (running a service in your infra), but then enables treating any part of your monorepo as an individual project repo.

git sparse-checkout can also work potentially, but does not cover the use case where you want to collaborate on some of your individual projects out of the monorepo context. That is, for example, you have a monorepo containing both private and and open source projects and you want to bidirectionally mirror the open source parts to a public site, like github.com.

initcrash
  • 46
  • 1