Skip to main content



      Home
Home » Eclipse Projects » EGit / JGit » How to manage multiple projects within the same repo(With independent branch switching)
How to manage multiple projects within the same repo [message #1849692] Sat, 29 January 2022 19:07 Go to next message
Eclipse UserFriend
What is the most common way of managing multiple projects within the same repo? For instance if you start each project on its own root commit, would that allow you to switch branches on each project independently from the other?

And how do you setup a root commit in the first place? Or alternatively if that's not the way, how would I go about creating the second project for this repo, normally?

Currently I have setup my second project from the non-git new project wizard, shared it by specifying the existing repo, and committed this onto a new branch based off the master branch of the first project. But I now have other branches in front of the master for the first project too, and each time I switch branches, the second project "disappears" completely from the package explorer.

I'm guessing this is because the second project is dependent on the current branch of the first project this way, and since it doesn't exist on some of the branches it gets automatically removed by git if I switch. But I want to be able to freely switch branches between the two projects as if they were from different repos. Or, that's my naive wish if that's what it is. I've just started using EGit this month so what do I know.

I've read most of the EGit User Guide, and I couldn't find specific instructions on how to manage multiple projects per repo, but it does suggest that it should be possible considering the folder structure of Repo > project > working tree.

[Updated on: Sun, 30 January 2022 03:47] by Moderator

Re: How to manage multiple projects within the same repo [message #1849697 is a reply to message #1849692] Sun, 30 January 2022 05:00 Go to previous messageGo to next message
Eclipse UserFriend
The straight forward way to version two projects independently is to put them in different git repositories.
You can have multiple independent version graphs in a single repository by adding multiple orphan commits having no parent.

Though you can checkout only a single version of a repository at the same time per working tree. Git supports multiple
working trees [1] for a repository, support for that in jgit/egit is still a work in progress [2].
Another way to achieve the same is to clone the same repository twice.

[1] https://git-scm.com/docs/git-worktree
[2] https://git.eclipse.org/r/q/topic:%22worktree%22+(status:open%20OR%20status:merged)
Re: How to manage multiple projects within the same repo [message #1849698 is a reply to message #1849697] Sun, 30 January 2022 05:31 Go to previous messageGo to next message
Eclipse UserFriend
Ah, I see. Thanks so much! I think I'll try cloning multiple times then. Because I want to observe the two projects at the same time, although they're closely related and might even share (duplicate) some files.

But in theory, how does having multiple orphan commits (root commits) work if you switch branches? This is what my head can't get around yet, as it looks to me that having independent orphans would mean both could checkout independently? I don't understand. I couldn't test this because I don't know how to properly create such an orphan, it kept associating the other project.
Re: How to manage multiple projects within the same repo [message #1861262 is a reply to message #1849692] Tue, 03 October 2023 02:40 Go to previous messageGo to next message
Eclipse UserFriend
I found this thread because I had the same requirement.

Using linux, I solved it by having the repository checked out completely (with two projects inside) outside the eclipse workspace folder and afterwards creating a symbolic link for each relevant project into the eclipse workspace folder.

I guess this should also work with windows using junctions.

This way, I can manage the repository from the command line, but inside eclipse git does not detect the projects to be under version control.
Re: How to manage multiple projects within the same repo [message #1861280 is a reply to message #1861262] Tue, 03 October 2023 14:45 Go to previous messageGo to next message
Eclipse UserFriend
A git repo can contain several disjoint acyclic version graphs consisting of commits and their parent relations, each starting from another orphan commit.
Branches (or more general refs) are just pointers to any of those commits.
If you version two projects A and B in two disjoint version graphs of the same git repository you can
only checkout a single branch per working tree at a given point in time.
This implies in a single working tree you can either checkout a commit of the version graph of
project A or a commit of the version graph of project B. As long as their version graphs are disjoint
there's no way to checkout a commit and have files from both projects in the same working tree.
Re: How to manage multiple projects within the same repo [message #1861303 is a reply to message #1849692] Wed, 04 October 2023 13:50 Go to previous messageGo to next message
Eclipse UserFriend
That sounds like I really should just use different repos, so they can checkout their own branches at the same time independently from each other.

Then I would have to ask a follow up question, how do I associate different projects (in Eclipse) so one can "run" on a selected version of the other, sort of as if it were a library? But I guess that question is probably outside the scope here.

Because both of mine essentially have a core/subproject relationship.

[Updated on: Wed, 04 October 2023 13:54] by Moderator

Re: How to manage multiple projects within the same repo [message #1861347 is a reply to message #1861303] Fri, 06 October 2023 14:56 Go to previous messageGo to next message
Eclipse UserFriend
You can import both projects into the same Eclipse workspace.
And checkout project A to some commit. And checkout project B to some commit.

If B is a library used by A and you want to version which version of B should be used by a version of A
you may consider to use git submodules to version this on source level. If you do this and checkout (recursively)
a version of A this will automatically checkout the version of B which is recorded by the submodule link
in this version of A.
See https://git-scm.com/book/en/v2/Git-Tools-Submodules
and https://git-scm.com/docs/git-submodule
Re: How to manage multiple projects within the same repo [message #1861350 is a reply to message #1849692] Fri, 06 October 2023 15:34 Go to previous message
Eclipse UserFriend
Ah, submodules. I haven't learned what that is yet, so thanks for helping me steer into the right direction.
Previous Topic:JGit update hook support
Next Topic:Git showing files are changed, but content hasn't changed
Goto Forum:
  


Current Time: Tue May 13 16:32:42 EDT 2025

Powered by FUDForum. Page generated in 0.04043 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top