gitsubproject

What are best practices for representing a git project's dependency on a local package with its own git repo?


I have a a local package dependency with its own git repository and I have a project that depends on that directory. What's the best way of synchronizing the project repository and its local package repository in sync?

One option is to merge the package as a subproject as described here:

How to Migrate Git Projects to Be One Project with Subprojects

However if I make changes to the package dependency I would need to merge that back in. Furthermore, one ends up maintaining two mirrored versions of the package. Is that the best practice in this scenario or is there a better solution?

Alternatively I could have a symbolic link to the package, but I'm not sure what's the best practice when a project has a git sub-repo that is symbolically linked.


Solution

  • For source dependencies, you have the choice between between:

    Both allow for evolution in the subrepo, but unless you are making constant changes, I prefer submodule: it allows to reference a fixed SHA1 of another repo.
    See more at "Differences between git submodule and subtree".

    The subrepo is referenced as a gitlink, a special entry in the index of the parent repo. You can still make commits within that subrepo as long as you commit and push them, then go gack one level up to the parent repo, add and commit the new SHA1 (gitlink), and push that too.

    You can reference a submodule in order to follow a branch (that is the -b master part)

    Any other project referencing the same submodule would need to do:

    git submodule update --remote
    

    They would get the latest from that branch (and would need to add and commit the new SHA1 resulting from the submodule fetch)