25

We have two different repositories on Git which need to come together to form the solution in Visual Studio.

Files under each project may be from the two different repositories. I need to make sure that when I make changes, it updates the changes in the correct repository (that is, the other repository should not perceive it at all) and also give me an option to add new files to a specific repository.

How can this be achieved, if can be done at all?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Samrat Dutta
  • 1,727
  • 1
  • 11
  • 23
  • Why do you want to store the files for one project in different repos? – Eddie Chen - MSFT Nov 22 '16 at 06:37
  • There is an upcoming feature for Visual Studio 2022 called "multi-repo support" that may be of help in these situations. https://devblogs.microsoft.com/visualstudio/multi-repo-support-in-visual-studio/ – ryancdotnet Apr 03 '22 at 23:09

2 Answers2

14

You can use submodules to realize it. Treat one repository as mainRepo and the other as subRepo.

  1. Based in the mainRepo and add the subRepo in it, use git submodule add subRepo’s_URL
  2. Just make changes on files you want. You don’t need to pay attention to which repository the files are from
  3. In the local mainRepo, use git commit –a –m ‘input your comment’, and then modified files from mainRepo can be committed
  4. In the subRepo (cd [subRepoFolderName]), you can also use git commit –a –m ‘input your comment’, so modified files from subRepo can be committed.

This may be different from want you thought, but it really saves you from which is the correct repository you want to update the changes in.

For more details about submodules, you can refer to here.

23W
  • 1,413
  • 18
  • 37
Marina Liu
  • 36,876
  • 5
  • 61
  • 74
  • As per this link: https://stackoverflow.com/questions/26951252/workflow-for-using-git-submodules-in-visual-studio#:~:text=As%20was%20mentioned%2C%20Visual%20Studio,manage%20an%20environment%20like%20this. ; VS IDE doesn't seem to handle submodules - though that post is dated 2014 so not sure but I hope now its handled – gawkface Mar 26 '21 at 02:14
  • Today is 2021, Visual Studio does not support submodules yet :( – 23W Dec 15 '21 at 06:43
-3

It's now easy with the Project Manager extension. (At least this is true in Visual Studio Code, and I suspect it's true in VS, since VS is a super-set of VSC)

This is what I did in VS Code, it should be similar in Visual Studio

Assume you have a Git-type repo set up, and you have a separate and distinct top-level repository for each part of the project that must remain distinct.

In GitHub, (or similar) you create the two repositories needed and import files as necessary.

If the repositories/workspaces already exist on the local development machine, make sure that the repositories are fully up to date.

In Visual Studio code install the Project Manager extension.

On the development machine(s), you create a "top level" folder for the entire project as a whole, then open the folder in VSC.

Then save that folder as a "Project" At this point you should "clone" the repositories to folders inside the top-level project folders. You clone the repositories to a new location because moving repositories is a PAIN IN THE TUSH and causes nothing but trouble.

Save each cloned repository as a "workspace"

At this point, you have a "project" containing two workspaces.

Move any folders/files that don't get cloned to the new repository location as necessary.

Once you do all this, (it's actually easier than it sounds), you have access to both repositories as independent objects, commits go to the correct repository, yet you can work on them side-by-side, (sort of) if you wish. You do this by opening the second workspace into a new window.

Hopefully this helps.

Jim JR Harris
  • 413
  • 1
  • 6
  • 15