Search code examples
gitvisual-studioversion-controlsolution-explorer

Visual Studio Solution from multiple Git repositories


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?


Solution

  • 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.