0

I often write some libraries for my own usage that I want to use in different projects. I would like to have a possibility to edit the library and make the changes valid in all the projects where the libraries are used. Until now I always had to do copy&paste.

I tried submodules but there seem to be many downfalls according to git submodules reference.

Are there better possibilities for this dependency management? What is the best practice for this?

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
himynameis
  • 23
  • 5
  • Typically you'd use the standard package-management approaches for the particular language you're working in. – Oliver Charlesworth Nov 12 '17 at 15:45
  • i'm quite a newbie. if i do C what would that be? – himynameis Nov 12 '17 at 16:11
  • Possible duplicate of [Git subtree or GitSlave as alternatives to Git Submodules?](https://stackoverflow.com/questions/6500524/git-subtree-or-gitslave-as-alternatives-to-git-submodules) – phd Nov 12 '17 at 18:05

1 Answers1

0

There are two situation to work with libraries for different projects. Assume the libraries in repoA, and repoB is one of the project repositories.

Situation 1: The libraries only work for you own (only manage libraries in repoA)

You can add the libraries from local repoA to local repoB directly:

In local repoB -> right click the solution for projectB -> Add -> An existing project -> Add the libraries from local repoA to local repoB -> commit -> push.

Now no matter where (in local repoA or local repoB) you changed the libraries, it's actually change the libraries in local repoA, So the libraries in local repoA and local repoB always sync.

Situation 2: other developers also need the libraries in projectB (manage libraries both in repoA and repoB)

If other developers also need to use the libraries, you should also manage the libraries in repoB. The ways usually used are git submodule and git subtree.

Since you have already tries submodules, I will only show git subtree as below:

  • Add the libraries (assume in master branch of repoA) to repoB:

      git subtree add --prefix=repoB <URL for repoB> master
    
  • If there has some changes in repoA, get the changes from repoA to repoB:

      git subtree pull --prefix=repoB <URL for repoB> master
    
  • If make changes for libraries in repoB, to push the changes to repoA:

      git subtree push --prefix=repoB <URL for repoB> master
    
Community
  • 1
  • 1
Marina Liu
  • 36,876
  • 5
  • 61
  • 74