There were some similar projects (projA and projB), which was developed separately and had similar files in it. No VCS was used.

After time, some 'library' (let's call it lib directory) same for both projects was developed. And git usage was started.

Now, I can't understand, what git functionality I have to use to? Submodule? Subtree? Something else?

The task is: track lib separately. But use it for projA , projB and other projects. And I want to 'git' older files of projects, where there were no separate lib. This need to support different versions of projA and projB - how it can be done with git? If possible - with some examples.

Thank you.


If lib is something used both by projA and projB I would make it a separate git repository to handle just lib changes, storing its history independently from anything else.

Then in projA and projB you would need to include lib in some way but that will mostly depends on how the projects are developed and deployed.

  • Thanks for the answer. Yes, tracking separately is a variant. And then build whole project with some 'build' script. But lib isn't full independent software - it's simply some code same for all projects. If I will track it separately - some time I will get confused in versions of projects and `lib' -this I'm afraid of. – Someone Feb 25 '17 at 15:35
  • 1
    It is not a problem if lib is not an independent software, it can be its own repository. The other way would be to have only one repository, and having lib, projA, and projB as separate directories in the repository, or if really useful git submodules but I think that these offer more drawbacks than benefits. As for the problem of versions, during deployment, projA and projB can specify the specific commit of the lib git repository that they should use (or better, use git tags inside lib repository) – Patrick Mevzek Feb 25 '17 at 16:27
  • Thanks again. Well, same thoughts I have. But was thinking there're more elegant ways in git to work with 'shared libs'... – Someone Feb 25 '17 at 16:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.