Taterhead
Taterhead

Reputation: 5951

Accessing code between branches with VS2015 simultaneously

I code in Visual Studio 2015 with git integration. Often times, I require to view code from different local branches so I can analyze parts of code from each branch at the same time and easily copy and paste code between branches simultaneously. This is different from merging existing changes from one branch to another. I need the ability to have 2 separate branches open on my screen at the same time.

Visual Studio has the ability to switch between git branches, but once you do this, all open Visual Studios accessing that git folder switches also.

I searched and found a solution, but it is not optimal: Check in everything and then duplicate the source tree one level above your .git directory. Open one Visual Studio on the solution from the original directory and then open a second Visual Studio instance on the solution in the copied directory. Each are independent of each other and you can have different branches open in one Visual Studio without effecting behavior of the other Visual Studio.

Does anyone have a solution to this issue that does not involve 2 copies of the source code?

Upvotes: 0

Views: 121

Answers (2)

Betty
Betty

Reputation: 9189

Git 2.5 finally has an answer for this, a feature called Git WorkTree.

https://git-scm.com/docs/git-worktree

A git repository can support multiple working trees, allowing you to check out more than one branch at a time. With git worktree add a new working tree is associated with the repository. This new working tree is called a "linked working tree" as opposed to the "main working tree" prepared by "git init" or "git clone". A repository has one main working tree (if it’s not a bare repository) and zero or more linked working trees.

add path [branch] Create path and checkout branch into it. The new working directory is linked to the current repository, sharing everything except working directory specific files such as HEAD, index, etc. - may also be specified as ; it is synonymous with @{-1}.

Upvotes: 1

PatrickSteele
PatrickSteele

Reputation: 14687

Does anyone have a solution to this issue that does not involve 2 copies of the source code?

No, but there is a workable solution (IMO) with two copies of the code.

First, I'm assuming you have some centralized repository that you cloned locally. And from your local clone, you have two feature branches (let's call them FeatureA and FeatureB). When you can do, is clone your local repository into a separate folder. In that new clone, checkout branch FeatureB. In the original clone (the clone from your centralized server), checkout branch FeatureA. Now you can do whatever comparisons you want -- albeit with two copies of the code.

This won't require you to check in any work you're currently doing in either copy of the code.

Upvotes: 0

Related Questions