sient
sient

Reputation: 620

Multiple git repositories with same base directory

I have two codebases, called a and b. Project a provides a common infrastructure that project b relies upon. However, all of the code for for project b is underneath the directory structure for project a. Here's an example:

a File0.cs
a Assets/Core/File1.cs
b Assets/Extension/File2.cs

So projecta provides File0.cs and File1.cs and owns the Assets folder. Project b only provides File2.cs

Does git support this directory structure? If so, how?

Thanks

Upvotes: 0

Views: 59

Answers (2)

user1046334
user1046334

Reputation:

Yes, it does. It is called "submodule" in git jargon. You can get help on it with git submodule --help.

Though, it is not seen as very good style to depend on submodules, if possible, use various package/dependency managers like pip, gem, npm, bower etc.

Upvotes: 3

tylerl
tylerl

Reputation: 30867

What you'er looking for is called a "Submodule":

6.6 Git Tools - Submodules

Basically you can tell git that a directory inside your repository is actually a separate repository, tracked elsewhere. This works at the directory level, not the file level.

From there, assigning individual files to a specific repository's directory is just a matter of creating symlinks.

myapp/
myapp/submodule/                    <-- submodule repository
myapp/submodule/foo.c               <-- shared file
myapp/foo.c -> submodule/foo.c      <-- shared file reference in parent dir

Windows support symlinks on NTFS, but it doesn't advertise the fact, making them slightly more difficult to deal with.

Upvotes: 0

Related Questions