Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reference files from one repository to another

Tags:

git

bitbucket

I have a git repository with a lot of source files. I would like to create a new repository, where some of the files from the existing repository is referenced into the new repository.

Example:

Repository A contains:

  • Directory 1
    • Source file 1
    • Source file 2
  • Directory 2
    • Source file 3
    • Source file 4

In Repository B I would like to reference source file 3 from Repository A:

  • Directory 3
    • Source file 5
    • Source file 3 from Repository A.

Repository B is going to be shared among developers who do not all have access to Repository A.

So my question is: Is it possible to reference some files from one repository to another, such that when developers with access to Respository A changes the original file the changes will be discovered by Repository B? If it is possible, how can I do it?

like image 584
ThomasCle Avatar asked Nov 05 '13 08:11

ThomasCle


1 Answers

Git thinks of files as the content of the whole repository, not as a collection of files. Therefore this is quite hard to do. If this feature is critical I suggest you switch to a file-centric SCM system.

However it is possible, but quite clumsy.

create an orphan branch in repo B with the file you want to track. Merge this file into an other branch in repo B, for example the master branch, possible using the subtree-merge algoritm.

You can use gitolite to restrict access to one branch from your repo. Now you can add repo B to repo A with as a submodule or as a remote and doing a subtree merge. (you can read more about how to handle submodules and subtree merges on git-scm.com).

However, you cannot use gitolite to deny reads from the whole repo B, just write access. If you're looking for read prevention as well, you'll need to put the file in a repo C

like image 96
iveqy Avatar answered Oct 16 '22 10:10

iveqy