3

Let's simplify the question considering the following scenario.

I'm working with three C++ projects stored in three different Git repositories. All projects need to live in a separate repo because they need to be independent during the development.

  • Project 1
  • Project 2
  • Common Code Project

To compile Project 1 you need Common Code version 1 (e.g. an older version). To compile Project 2 you need Common Code version 2 (e.g. a newer version).

Sometimes you want to work with the Common Code Project as a standalone project (kind of a standalone shared library), compile it, do tests, and possibly advance with new versions, branches etc.

Project 1 and 2 will keep their stories and they are likely to require different old versions of the Common Code for the compilation even if the Common Code advances in its personal story.

I need to work on all the projects on the same machine switching multiple time between them in the same day, so the working model can't be too complicated to avoid errors or problems.

Should I work with 3 parallel repositories resolving the compilation dependencies on the version at compile time (e.g. by checking out the correct version of the repo before compiling)? Is there any other better solution (e.g. Git Submodules)?

turbopapero
  • 932
  • 6
  • 17

2 Answers2

3

This sounds like a git submodules task. With submodules, you can reference another repository at a specific revision.

How to check out specific version of a submodule using git submodule?

Community
  • 1
  • 1
Chris Cooper
  • 17,276
  • 9
  • 52
  • 70
1

You could use

  1. git submodules (not really recommended, hard to maintain, git will go into bizarre berserk states if you mess up - e.g. delete a submodule directory from underneath git, so it's really fragile)
  2. git subtrees, probably in a more convenient form of git subrepo (https://github.com/ingydotnet/git-subrepo) - this causes some code duplication so i'd also be cautious about using it, especially if projects are large.
  3. repo tool - https://code.google.com/p/git-repo/

With repo you need to set up a manifest repository which will describe from which repos, which revisions and into which directories to populate project parts. This allows you to develop components completely independently, and lock to certain versions of these projects together with keeping clear history - the manifest repository is versioned separately and can have marks for specific releases of software.

berkus
  • 1,552
  • 12
  • 16