We're in the process of converting from Subversion to Git and one thing that I'm struggling with in Git is the method of switching branches.
My understanding is that at both at the command line and using EGit in Eclipse that switching to a different branch replaces the contents of the Eclipse workspace folder with that of the desired branch. This implies only one branch can be open at any one time.
In SVN I could arrange my Eclipse workspace similar to:
Workspace/
Project1Branch/
Project2Branch/
Project3/
Project4Branch/
Is it possible to have multiple Git branches open at the same time in the same Eclipse/Egit workspace ( or any other environment for that matter )?
Git offers a feature referred to as a worktree, and what it does is allow you to have multiple branches running at the same time. It does this by creating a new directory for you with a copy of your git repository that is synced between the two directories where they are stored.
With Eclipse Neon (and probably Mars too): right-click on a connected project > Team > Pull... . Select to pull from the master branch.
After much testing and a sanity check from @MarkLeightonFisher it seems it is not possible to have multiple Git branches open in the same Eclipse workspace at the same time.
Indeed you can't import multiple branches from the same git repository into the workspace, because it only has one working directory which can contain only one checked branch. Here's a very reasonable workaround that accommodates this feature of git (I do it and it works well): Clone the git repository in a second directory (or 3rd or 4th even), then change the name of the project manually by editing .project and changing the <name> element. You can now import this project alongside the original, and work on multiple branches at the same time in the same workspace. Caveat: Get very friendly with the "Close Project" menu item so you can avoid cross-editing (it gets confusing sometimes when you have many source windows open with the same file name...)
Actually i managed to do it :
You can have multiple workspaces for one git repository : this is called "worktree". (limitation is that for obvious reason, you can't checkout same local branch in 2 different work trees. Well, you shouldn't, but some commands may lead you to be in such situation.)
https://git-scm.com/docs/git-worktree
Then you can create one eclipse-workspace for each of your work-tree.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With