1

This surely has to be a duplicate since its a common scenario, if so pls direct me to a good link.

I have common project (class library) that will be used across many solutions, say, a common solution which I will call dll shared between solutions A and B. So this is how the directory structure right now is:

Solution Common (dll)
      - Project Common

Solution A
      - Project A1

      - Project A2

      - Project Common #only referenced, so logical presence, not in real

Solution B
      - Project B1

      - Project B2

      - Project Common #only referenced, so logical presence, not in real

Now what I need is

  1. a git repository in dll so that I can commit the changes i make to dll files.

  2. a git repository in A so that I can commit the changes i make to files of A as well as dll files. (Since in visual studio I have both projects under one solution, editing them both is easy but I should be able to commit them both together). Also it would be welcome if I could pull any specific commits of dll that was made from dll repository, but its not absolutely necessary.

  3. Same as above for B.

Basically I need 3 repositories so that I can individually commit in 3 different solution folders but I also need the ability for dll repository to be shared between A and B from which I can commit and pull etc.

My questions are:

  1. Is it possible?

  2. If so how would I structure my repositories?

  3. How will I commit/pull dll and A together?

One solution that is already coming to me is to have one giant repository for all the 3 solutions outside its scope but that seems so inelegant as I have other solution folders too along with A and B.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
nawfal
  • 70,104
  • 56
  • 326
  • 368
  • Are you looking for [git submodules](http://www.kernel.org/pub/software/scm/git/docs/git-submodule.html)? – madhead Feb 22 '13 at 20:43
  • @madhead I dont know what they are, but will look into it – nawfal Feb 22 '13 at 21:02
  • @madhead spot on, indeed helpful, though I find the [official documentation](http://git-scm.com/book/en/Git-Tools-Submodules) posted by VonC much simpler to follow – nawfal Feb 22 '13 at 22:05

1 Answers1

1

I confirm this is what git submodules (mentioned by madhead) are for, but you need to realize that a submodule is first a fixed reference to another repo.
You can make modifications directly in a submodule, but you need to:

  • commit in that submodule, and pushing to its upstream repo
  • cd back to the parent repo
  • commit in that parent repo (recording the new reference for the submodule) and pushing to the parent upstream repo

(See more in the "true nature of submodules)

This is well suited for a component-based approach, where each module can evolve independently, and specific revisions of said modules are combined in order to form a complete program.
(your "giant repo" would be a system-based approach, where all modules are writable, and in their latest revision)

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • but isn't each individual commit to `dll` solution (be it from `A`, `B` or `dll` repo) treated as individual branches? In other words, if I change `dll` files from `A` and commit and push to `A`'s central repo, would I get the same change in `dll` and `B` when pulling? – nawfal Feb 22 '13 at 21:30
  • @nawfal if you are pushing to and pulling from the same upstream branch, then yes, `dll` in `B` will get changes made in `dll` in `A`. – VonC Feb 22 '13 at 21:32
  • VonC, can you clarify what is "same upstream branch"? I'm new to these terms. Did you mean "central repo" by that? I have separate central repositories for `A`, `B` and `dll` in bitbucket/github etc. Can I make changes to `dll` from local repo of `A`, then push to central repo of `A`, and then get the same set of changes for `dll` from `B`'s central repo when pulling? – nawfal Feb 22 '13 at 21:33
  • @nawafal: an upstream branch is a branch on your upstream repo: see "upstream" at http://stackoverflow.com/questions/2739376/definition-of-downstream-and-upstream/2749166#2749166 (and the answer below: http://stackoverflow.com/a/6244487/6309). You usually are making a local branch to track an upstream branch: http://stackoverflow.com/a/12969042/6309 – VonC Feb 22 '13 at 21:38
  • Von, I will inspect that and get back to trouble u more :) Your help is much appreciated.. – nawfal Feb 22 '13 at 21:39
  • 1
    @nawfal: on tracking branch: http://stackoverflow.com/a/4697054/6309 and http://stackoverflow.com/questions/1070496/having-a-hard-time-understanding-git-fetch are instructive posts. – VonC Feb 22 '13 at 21:40