Issue
I need to open 2 Visual Studio instances: one will be to just look at the code of the Project X / Branch 1, and the other will be used to code in the Project X / Branch 2.
How can I do that without losing changes when committing?
Solution
The issue here isn't to do with Visual studio, but how Git works. When you check out a branch in git, it places that branch into your working tree or (file structure, whatever you wish to call it).
With git you can only have one branch checked out at a time, but wait there is a solution!
By utilising the git worktree
command, you can create a second worktree for the same repository in a different directory. You can then open that work tree in visual studio to have two different branches checked out.
Let's say you have C:\projects\the_project
and you want to make a new work tree at e.g, C:\projects\the_project_2
, open git bash, navigate to the project's directory and run
git worktree add ../the_project_2 <branch>
where is the branch you want checked out in the new work tree.
This will create a new directory "C:\projects\the_project_2")
and checkout the branch into it, without having to re-clone the repository.
For more information see the git worktree documentation.
Note: Earlier versions of Visual Studio does not know how to treat additional work trees, and will not recognise them as git repositories.
Answered By - Ripp_ Answer Checked By - Cary Denson (PHPFixing Admin)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.