3

I have a set of related repositories that I want to manage.

The data I want to store are "projects" that consist of "libraries" which consist of "units". Each library is stored in a subfolder of the project, and each unit is stored in a subfolder of a library.

To be able to reuse libraries and units between several projects I plan to store them according to this scheme:

repositories/projects/project1
repositories/projects/project2>
repositories/projects/project...
repositories/libraries/library1
repositories/libraries/library2
repositories/libraries/library...
repositories/units/unit1
repositories/units/unit2
repositories/units/unit...

I'd like to reference the libraries used in a project relatively (say uses ../../libraries/library1) and to reference a unit in a library also relatively.

Libraries and units can only be modified by modifying a project containing them. So the library and unit repositories could be bare if it's necessary.

The repository on the server should look the same (same layout of folders).

I've already tried using submodules and the "read-tree/subtree merge" approach but couldn't find a way to specify relative urls to repositories in the submodule case and to push changes in the read-tree approach.

What I'd like to accomplish is that if I check out project1, it also fetches all libraries and units necessary and if I change a library or unit through a project these changes can be easily pushed to the server again.

CharlesB
  • 86,532
  • 28
  • 194
  • 218
Onur
  • 5,017
  • 5
  • 38
  • 54

1 Answers1

2

Submodules are the way to go for you, and allow relative URLs.

A submodule can specify another submodule URL relative to the superproject's origin URL. So in project1, use the following

git submodule add ../library1
git submodule --init update

And it should be fine: library1 will be checked out in project1's directory, its original repo being next to project1.

CharlesB
  • 86,532
  • 28
  • 194
  • 218
  • Just to make sure I get it right. If someone clones a project, the submodule's origin will be the local clone, i.e. when cloning the relative url will remain relative? – Onur Apr 23 '12 at 09:15
  • It depends from where project is cloned, I'm sure it works if everybody clones from your central repository, because submodule URL specified for project1 will still be relative to your central repository. If you clone from a coworker's repo, `origin` will have to be manually set to your central repo – CharlesB Apr 23 '12 at 09:28