How to use Git worktrees with Eclipse IDE?
Asked Answered
W

1

13

I am moving a large application from SVN to Git while only having read "pro Git" and some worktree details online and played around with Git.

I created a single repository that manages the code of my application. My application consits of a lot of different Eclipse projects that are of Maven nature and are released separately. I created a remote branch for every Eclipse project, as suggested. Now I want to checkout some of those Eclipse projects in parallel, at newly created individual feature branches, to implement a new application feature that affects more than one Eclipse project.

Here, on 28.08.2019, Andre Bossert stated that Eclipse is able to detect and support Git worktree directories. But I just fail to hit the right button in Eclipse, it seems. Can anybody point to a documentation of Eclipse egit where I can find further information, please? I also failed to find this information by myself.

Weismannism answered 19/12, 2019 at 9:33 Comment(10)
Could please show how the repository is displayed in the Git Repositories view? Besides that, I don't think Git worktrees is the best choice in your case. It sounds like you're trying to mimic SVN in Git: checking out different subdirectories of different branches as different projects. In SVN, a commit creates a new revision, whereas in Git, a commit is a change that can easily be applied to other branches.Sonata
Have you tried adding each of the work trees as a separate repository in the Git Repositories view?Sonata
Vert.x project created a repository per module at Github. That's what I could do easily. But I would like to keep the application context. Also internet search told me it seems best practice to manage a modular app via branches within the same repository. The worktree feature seems to perfectly fit my needs though the IDE support seems to lack. But again, I am new to Git. Maybe I am getting something wrong. Is someone managing a large scale modular application with multiple Git repositories instead of a single one out there? Though, focus of my question was Eclipse and how to use worktrees.Weismannism
Have you tried adding each of the work trees as a separate repository in the Git Repositories view? Having branches per project in a single repository is fine, but to check out those branches in parallel via Git worktrees instead of creating a new branch and pull all required branches into the new branch, sounds in Git a bit special.Sonata
Yes, I tried this and failed. I clicked "add existing local repo". There was nothing to select. Message: "Found no repo scanning", I told it to look in "/Git" and "/Git/trees". Before this I used cmd line "git worktree add ~/git/trees/branchxyz" to create a worktree. To pull multiple required into a new one never occured to me. Would mean you'd have to have Eclipse project dir under a branch root dir, right? I also thought to avoid that and have pom.xml and .project etc. directly besides .git file. So your structure is: "/branch-xyz/project-xyz/.project"?Weismannism
Please edit your question to show your file structure. Why don't you want to create a separate branch for the application into which you pull the project branches?Sonata
So you suggest to live with the limitation of the single working directory by working on a joined branch with all projects required. And when I am done I just have to push every project back to it's master branch, right? Regarding the file structure, I don't have any with Git, yet.Weismannism
I wasn't suggesting that. Instead, I would recommend tracking the application in a separate branch to avoid all the extra manually work required to manage the worktrees (which are intended for other cases). You still stuck in the SVN way of thinking.Sonata
Seems like we should have had a chat about this. Comment section of stackoverflow has too little characters. I suggest I'll get some practice with Git and re-read your input then again. Let's focus on how to get Eclipse to detect Git worktrees. What do I have to do?Weismannism
Using Eclipse 2020-06, git worktrees do not seem to be recognized. I cannot import an existing worktree as a git repository (Eclipse does simply not find a repo there), and a project opened from an existing worktree displays no team/git information in Eclipse. I am not sure about your link to the bug: While that comment seems to say that parts have been implemented, it seems to me like nothing of that has yet made it into any official Eclipse release.Idiomorphic
C
8

tl;dr As of March 2021 April 2023, the Eclipse IDE does not support Git worktrees.


Longer answer:

Unfortunately, the Eclipse IDE as shipped by the Eclipse foundation does not support the worktrees created by git-worktree.

There is an open bug for this - Bug 477475 - git 2.5 worktree support. The bug was reported in 2015 and is still open.

There has been quite a bit of work on the problem, and a (mostly?) working implementation exists, as discussed in the bug and in the linked Gerrit changes, but that code has not made it into any release so far.

As of March 2021, the latest work seems to be the Gerrit change 163940: Add git-worktree support for already created worktrees, last updated December 2020. So we can only wait and see... or help with coding :-).

Chopping answered 31/3, 2021 at 9:48 Comment(2)
Thank you for this qualified answer. I also came to the conclusion to better avoid it for now.Weismannism
"Status: NEW ". LOLRuberta

© 2022 - 2024 — McMap. All rights reserved.