Search code examples
gittfsversion-controlgit-subtreemonorepo

Git Subtrees vs Monorepo


We recently decided to move from TFVC to Git and I'm trying to find the best way to design our new Git architecture.

Our code is made of independent but tightly coupled modules, let's look at the following projects:

  • CommonLib1

  • CommonLib2

  • ApplicationA (uses CommonLib1)

  • ApplicationB (uses CommonLib1 & CommonLib2)

Although CommonLib1/CommonLib2 are completely independent, almost every new feature for ApplicationA/ApplicationB would require modifying CommonLib1/CommonLib2.

Moreover, when adding new features we would like to create a single branch that would span between all our projects.

As far as I understand, I'm left with 2 main options:

  1. Create a repo for each project, and add CommonLib1/CommonLib2 as subtrees in ApplicationA/ApplicationB.

  2. Create a single Monorepo for all the projects.

What would be the best Git practice for my situation?


Solution

  • Since CommonLib1/CommonLib2 are closely related with ApplicationA/ApplicationB, so you’d better use option2 (create a single Monorepo for all projects). The branches structure can be as below:

    • Lib1 branch: manage/develop/update CommonLib1 in this branch. When it’s updated, you can merge it in appA and appB branches.

    • Lib2 branch: manage/develop/update CommonLib2 in this branch. When it’s updated, you can merge it in appB branch.

    • appA branch: manage/develop ApplicationA project.

    • appB branch: manage/develop ApplicationB project.