How to Link 1 git repository to some other repositories ?
Assume I have following repositories :
/var/Common.git
/var/Project1.git
/var/Project2.git
Now, I want to use Common.git in other repositories. how can I do it ?
How to Link 1 git repository to some other repositories ?
Assume I have following repositories :
/var/Common.git
/var/Project1.git
/var/Project2.git
Now, I want to use Common.git in other repositories. how can I do it ?
You're probably looking for submodules:
A key word there is embedded: an actual clone of Common.git would be embedded inside each of the other projects. This is generally good for when you're not going to modify it inside the other projects, just use one version, and update that version from the original Common.git now and then. You'd do something like this:
Note that the path to the submodule is going to be committed to your repository, so you should use a publicly available URL. If you want to customize it locally, you can run
git submodule init
, edit the url in .git/config, and then rungit submodule update
. If you have further questions, consult the manpage or search SO; there are plenty of submodule questions here.If on the other hand you're going to be editing the contents of Common.git inside each of the projects, you may want to use git-subtree, which is a friendly wrapper around git's subtree merge faculties. That will let you regard the contents of common.git as tracked content inside each of the projects, while still being able to split out commits to it and merge them into Common.git itself, and merge updates to Common.git back into the projects.
This is a perfect case for which
git submodule
was designed: http://git-scm.com/docs/git-submoduleWithin the Project1 and Project2, you add submodule of the Common. And then you
git submodule checkout
In the cloned repo it only stores the hash of the Common git. So you
git submodule init
and checkout.