1

I have a number of git repositories at school that I want to manage & share at once, so that I can work on them at home too.
But I don't want to create remote repos for each of those repositories.

Folder structure:
-- basefolder
| - project1 (repo)
| - project2 (repo)
| - project3 (repo)
...

What I want is to have single repo (basefolder) that contains each of the 'subrepos'. As if I'd copied the folder (basefolder) using usb/dropbox etc.

I thought submodules were the way to go, and I researched submodules, and created sample repositores to try it out.

I created submodules with relative paths, but cloning the 'superproject' then submodule init && submodule update doesn't get me the files from the submodules. The urls are local & don't exist on a different machine.
Having remote repos for each 'sub-repo' (project 1~) would make this work, but as I stated above I don't want to create separate repos for each project.`

I also know that I can concatenate them into one repo (basefolder), but I'd like to keep the histories of each project separate.

EthanHlc
  • 11
  • 2
  • A repository never *contains* another repository. With a submodule, you include in the "superproject" two things: (1) instructions (recorded in `.gitmodules`) for how Git can run `git clone` to get a second repository, and (2) one commit hash ID (recorded in any one given commit) to *check out* from the submodule. The end result is inevitably two or more separate Git repositories: the superproject, plus its submodule clones. – torek Dec 08 '22 at 08:14
  • This does seem like what you want, so I'm not sure what your particular objection is to submodules. However, submodules are a royal pain in general, and I'm generally of the opinion that even when submodules are the right answer, they're still the wrong answer... I just have no "righter" answer. – torek Dec 08 '22 at 08:16

1 Answers1

0

Another option, which would:

  • use only one repository
  • avoid submodules entirely

would be to use one branch per project.

That way:

  • each branch represent the history and commits related to only one project
  • using git worktree (to manage multiple worktree), you can still have one local basefolder, and in it, one folder per project, without having to clone the same repository n times.
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250