How to Link 1 git repository to some other repositories?

You're probably looking for submodules:

Submodules allow foreign repositories to be embedded within a dedicated subdirectory of the source tree, always pointed at a particular commit.

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:

# add Common.git as a submodule at the path "common" inside this repo
git submodule add /var/Common.git common
# initialize it, clone, and check out a copy
git submodule update --init
# commit the addition of the submodule
git commit

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 run git 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-submodule

Within 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.

Tags:

Git

Repository