jvoigt
jvoigt

Reputation: 432

How to handle shared files(dlls) in multiple unrelated projects

I am currently tasked with porting our repository from SVN into GIT. While I am doing that,I was going to try and break some of our mostly unrelated areas. We will say that we have some projects in ExternalCustomerCommunications that use projects with ABC.cs and we have InternalUser UI code that also uses that some file and project dlls. Of course if I left all that code in one repo currently but and in doing so they can share the ABC dll inside the solutions becuase they are all in the same repository. Due to the size of our repository and the two parts residing in two complete different servers and applications, I thought breaking some parts out might make sense.

My question is, in order to do that, how would one handle the two repositories both wanting the same shared code? I understand that a subtree might be a solution but I was not sure if that is advisable. I read may posts on the horrors of subtrees and submodules.

I would think this is a fairly common situation but I did not know of any best practices for handling it.

I also believe that I read that a single solution either could not or should not have two repositories to it.

If it matters, I am using VSTS and their hosted instance of GIT as well as visual studio (and perhaps sourcetree if it lends itself well to the process)

Upvotes: 1

Views: 1645

Answers (2)

Marina Liu
Marina Liu

Reputation: 38116

Assume SubRepo is the git repo which manage the referenced project (ABC.cs), the the MainRepo is the git repo you want to add references from the external repo (SubRepo). Below are the ways to achieve by submodule and subtree separately:

Option 1: Submodule

To add SubRepo as a submodule for the MainRepo, you can use below commands:

# In the directory of the local MainRepo directory, such as C:\MainRepo
git submodule add <URL for SubRepo>
git commit -m 'add SubRepo as a submodule for the MainRepo'
git push

Now all the files of the SubRepo are add in the sub-directory C:\MainRepo\SubRepo, then you can refer files under the sub-directory, commit and push and changes.

Note: If files in SubRepo are updated, you can update the submodule in your MainRepo correspondingly with below commands:

git submodule update --remote
git commit -am 'update submodule'
git push

Option 2: Subtree

To add SubRepo as a subtree for the MainRepo, you can add files of a SubRepo's branch into subdirectory of the Mainrepo. Commands to add a subtree as below:

git subtree add --prefix=subfolder <URL for SubRepo> master
git push

Now git add the files of the SubRepo's master branch into the subfolder subfolder of the MainRepo, merge and commit the changes into your MainRepo.

Note: If files are updated in the SubRepo, you can update the subtree of the MainRepo with below commands:

git subtree pull --prefix=sub <URL for SubRepo> master
git push

Upvotes: 1

Marcin Natanek
Marcin Natanek

Reputation: 576

Your GIT repositories should be as lightweight as possible and build, test, deployment and dependency management should be handled by some config files. The config files format is usually determined by the used framework or automation tool. In JavaScript, for example, you would use npm package manager, to list your dependencies and keep them outside the repository. If you want to share code between two repositories, you create the third repository with new npm package, and then in other repos you can use package.json (npm configuration file) to specify the shared code repository to pull code from during dependencies installation.

If you need build, test and deploy cycle for the shared repo as well, you should publish your artifacts to some special repository, that is build for the purpose (I heard good things about artifactory)

I see that you mentioned ABC.cs so I infer C# language. There is a NuGet package manager that you could investigate for the purpose.

There are also solutions, like GIT LFS, for keeping large files, but I have never needed to use it.

Upvotes: 0

Related Questions