7

I have two different .Net projects, hosted on github.

I would like to create a shared "commons" library for the two projects.

How should I structure my repository to facilitate this sharing?

Ideally, a change in this common library in one project could easily be pushed into the other project. I prefer to keep the code itself editable from the two projects (within Visual Studio), and not include it as a library. Are there best practices for this?

ripper234
  • 222,824
  • 274
  • 634
  • 905

2 Answers2

6

You can use the Git submodules: https://git-scm.com/book/en/v2/Git-Tools-Submodules

Esko Luontola
  • 73,184
  • 17
  • 117
  • 128
  • You do `git submodule add path-to-shared-repository` in each repository. A sub-directory with the name of the shared repository will be created. This question is relevant here : http://stackoverflow.com/questions/1462754/what-is-the-advantage-of-using-git-submodules-over-having-a-repo-inside-another –  Apr 04 '16 at 04:04
  • 1
    This is so weird. I only wanted to fix a broken link. I could not do it because it was too small, don't ask me why. I did not know what to add, because I did not know about submodules. So, I added a sentence, so that I could fix that broken link. It was accepted. Later, when I tried to replace that useless sentence by something more useful, it was rejected. So, we are left with that useless sentence. –  Apr 04 '16 at 04:11
1

Git submodules is probably not your answer. See this blogpost that goes into further details: http://blogs.atlassian.com/2013/05/alternatives-to-git-submodule-git-subtree/

Emil Kantis
  • 1,069
  • 7
  • 17
  • Regarding git-subtree (from your reference): The downside is that all of your subproject files are present in the parent repository, which means you’re giving up some of the reason for originally splitting up your project repositories: having one canonical repository for a given set of shared code. If someone makes a change to a subproject, they can merge it with other changes locally, but they’d have to explicitly split that change back out of their project if they wanted to share it with projects. –  May 27 '16 at 15:16
  • But, I agree that some other options https://codingkilledthecat.wordpress.com/2012/04/28/why-your-company-shouldnt-use-git-submodules/ are perhaps better. –  May 27 '16 at 15:21