Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple Git Branches in Multiple Eclipse Projects

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 )?

like image 594
Greg Kennedy Avatar asked Jan 28 '13 15:01

Greg Kennedy


People also ask

Can I have multiple branches in git?

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.

How do I pull a different branch in eclipse?

With Eclipse Neon (and probably Mars too): right-click on a connected project > Team > Pull... . Select to pull from the master branch.


3 Answers

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.

like image 93
Greg Kennedy Avatar answered Oct 21 '22 10:10

Greg Kennedy


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

like image 42
A. Assaad Avatar answered Oct 21 '22 11:10

A. Assaad


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.

like image 30
Pellekrino Avatar answered Oct 21 '22 11:10

Pellekrino