Search code examples
eclipsegitgit-submodulessubdirectorygit-subtree

How to make a separate Eclipse project out of a subfolder under Git source-control


I have a website project with the main files in a root folder and an admin tool in a subfolder. The admin tool includes a few classes from the root folder.

I would like to keep separate version control over the 'site' (root) and the 'admin tool' (subfolder) with Git. With Git ignoring the subfolder in the root and a separate repository in the subfolder this works fine.

However, I like using Eclipse (4.4.2) as my Git GUI but Eclipse manages this on a project basis and when I try to create a new project in Eclipse of the subfolder it complains that this is not allowed because that folder is already part of another project (root folder).

Is there a way, just like in Git, to make Eclipse ignore a subfolder in a project so that I can create a separate project of the subfolder? Or should I approach the whole thing differently?


Solution

  • Eclipse unfortunately doesn't visually indicate separate changes when using submodules and managing the root folder and the subfolder as separate projects in Eclipse helps me to keeps things separately organized. That is why I chose to .gitignore the subfolder in the rootfolder and create a separate repo in the subfolder.

    Bringing this to Eclipse was a hassle because there are some known bugs in Eclipse that (ironically) make EGit ignore the .gitignore file. This makes Eclipse insist on committing the .git folder it finds in the subfolder as a submodule, even though it should be ignoring it.

    I now have everything setup using the following steps:

    1. creating a symbolic link (Windows) of the subfolder to a folder next to the root folder. This helps bypass the Eclipse restriction of creating projects in subfolders of folders that are themselves already a project.
    2. creating the repos before adding the projects to Eclipse, otherwise Eclipse will not use the .gitignore file. Even if you use EGit to create them.
    3. Writing the .gitignore file with Unix style line breaks, using a forward slash to ignore the /subfolder. Git itself handles other formats fine but Eclipse won't use the .gitignore correctly if it isn't exactly written that way.
    4. To clean things up; hiding the subfolder from the 'site' (root) project by adding a Recourse Filter on the project that hides the subfolder from the project tree. This way, the file from the 'admin tool' subfolder can only be accessed in Eclipse through its own project.

    I now have two separate projects in Eclipse with each their own Git repository, even though one is technically a subfolder of the other. I wrote a details tutorial about this in this post about managing a subfolder as a project in Eclipse, Git and FTP.