How to open 2 instances of Visual Studio with the same Git projects and different branches

I need to open 2 instances of Visual Studio, it will be open for me to just look at the code for Project X / Branch 1. Another, will be used for encoding in Project X / Branch 2. How to do this and not lose the changes in the commit operation?

+16
source share
2 answers

The problem here is not in the visual studio, but in the work of git. When you fetch a branch in git, it puts that branch in your working tree (file structure, as you want to call it).

With git, you can only check one branch at a time, but wait, there is a solution! Using the git worktree you can create a second working tree for the same repository in a different directory. You can then open this working tree in Visual Studio to test two different branches.

Suppose you have "C: \ projects \ the_project" and you want to create a new working tree, say, "C: \ projects \ the_project_2", open git bash, go to the project directory and run git worktree add../the_project_2 <branch> where is the branch you want to check in the new working tree.

This will create a new directory ("C: \ projects \ the_project_2") and extract the branch into it, without having to clone the repository again.

See the git worktree documentation for more information.

Note. Earlier versions of Visual Studio did not know how to handle additional working trees, and did not recognize them as git repositories.

+10
source

If you need to open the code in Visul Studio, you need to issue a branch. Since you cannot retrieve two different branches in the same directory at the same time, you cannot avoid retrieving each branch in a separate directory.

But you can install the remote git directory from one directory to another so that you can sync locally and not need any external ones.

Suppose you want both branches to be subdirectories of the ProjectX root shared directory:

 cd ProjectX git clone -b branch1 <remote repo of project X> directory_branch1 git clone -b branch2 directory_branch1 directory_branch2 

May 2019 update: since git woorktree now works and is supported by GUI-based tools, this is probably the solution you can use today.

+1
source

Source: https://habr.com/ru/post/1247316/


All Articles