1

I have multiple Python codebases, 4 git repos, that use a common set of functionality that is copied in all 4 repos. When I modify one, I need to make the change in all 4 repos manually.

The repos structure is like so:

repo-1
\ src-1
\ test-1
\ other-1
\ common-code


repo-2
\ src-2
\ test-2
\ other-2
\ common-code

... (similar for repo-3 and repo-4)

Each repo conda-builds its own package and tests it agains a Docker image.

What is the right way to set these up correctly?

Sqandr
  • 75
  • 1
  • 7
  • 2
    You should create a new repository for the common functionality. Then in each of those 4 repositories, add a git submodule for the new repository you created. – thuyein Jun 06 '19 at 02:02
  • I had this simple idea but couldn't remember the git word for it; `submodule`. Thank you! But is this the best/correct way of doing it? Can you explain what the whole picture would be from a build, test, CI, and CD perspective? – Sqandr Jun 06 '19 at 02:10
  • 1
    I think in terms of CI/CD, it would just be modification to the [git clone command](https://stackoverflow.com/a/4438292/1509809) for the existing 4 repos. Then you probably have to extract out the tests for the `common-code-repo` and do it in the same repository. – thuyein Jun 06 '19 at 02:15

1 Answers1

1

In addition to git submodule, which allows your 4 Git repositories to reference a fifth one (common), you will need, for each modification on common, to do:

cd project1
git submodule update --remote
git add .
git commit -m "update common"
git push

That way, your CI/CD can clone any of your main project with submodule (as Jenkins does, for instance)

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250