46

I am a typical Eclipse/Subversion user beginning the migration to Git. I've researched the basic concepts of git and have decided to stick to a one project per repository approach initially to keep things simple. I am still having trouble, though, deciding where to place the repository for each project.

I have spent a lot of time reviewing the answers to this question, although I believe the author of that question was assuming that you can only use Eclipse to manage the repository if the repository is located within the Eclipse workspace, which is, of course, not true.

The thing that struck me most about that question, though, was the fact that all but one answer (including the accepted answer) suggested keeping the repository inside the Eclipse workspace, whereas only one answer pointed out that the EGit User Guide recommends the exact opposite.

It would appear in practice, however, that there are a number of approaches implemented by Eclipse/EGit, some of which seem to contradict the EGit recommendations.

For example, if you use the New Project Wizard to create a New PHP Project from Git and the repository is remote, Eclipse/EGit will happily create a project folder in the Eclipse workspace and put the repository (.git) in the project folder. This is the end result that I actually want, as it keeps everything encapsulated within the Eclipse workspace.

However, if you use the New Project Wizard and select a Git repository that is local, Eclipse/EGit doesn't clone the repository like it does for remote repositories. Instead it uses the working copy of that repository as the project location, creates its .project and other meta stuff in that location and also creates a new (seemingly unnecessary) folder within that working copy with the same name as your project (so you end up with, for example, ~/git/blah/blah). If you delete that superfluous folder you end up with a structure that is identical to the first example, the only difference being that the project folder is not a sub-folder of your Eclipse workspace folder, it is somewhere else on your file system (eg. ~/git/blah). The only positive thing this approach seems to have going for it is that it adheres to the recommendations in the EGit User Guide, but from a technical perspective, its hard to see how this is really all that different to the first example.

Given these puzzling observations, I'm wondering what sort of experiences people have had using each of these approaches and what the pitfalls might be if one ignores the recommendations in the EGit User Guide.

Community
  • 1
  • 1
JamesG
  • 4,288
  • 2
  • 31
  • 36
  • possible duplicate of [Should I store git repository in Home or Eclipse Workspace?](http://stackoverflow.com/questions/7685246/should-i-store-git-repository-in-home-or-eclipse-workspace) – mallardz Jun 19 '14 at 12:38
  • @JamesG What approach do you take to reflect the changes in workspace to your git directory? Is there a better alternative to copy pasting the source code? – Sudip Bhandari Nov 14 '16 at 13:45
  • 1
    I don't use Eclipse any more - I use PHPStorm - so I just clone into a project folder and then start working in there. I don't think PHPStorm even provides the option to store the repository in a different folder to the project. Honestly, based on what I've heard and read since posting this question four years ago, I don't think many people would be storing their repositories outside their project folders any more. – JamesG Nov 14 '16 at 22:26

2 Answers2

28

The implications of both solutions are listed directly in the user guide that you linked. I can tell you that the part

This can result in performance issues

is unfortunately very true. So if you have a git directory with a huge number of files inside your workspace, many git operations will start with a "counting objects..." dialog that blocks your IDE because it scans all files in the workspace. For my current 20000 files this means waiting 10 to 20 seconds for every commit, every switch, ...

In spare time activities, where I can fortunately use the other alternative (having the git working directory outside the workspace) everything feels much snappier and it is fun to merge and switch.

So if you go for large projects, consider the git directory outside the workspace as first choice.

Bananeweizen
  • 21,797
  • 8
  • 68
  • 88
  • I'll add that Eclipse and EGit itself set themselves up to use their git repos outside of their workspace, and it's been working fine. – Paul Webster May 10 '12 at 11:54
  • 3
    @Bananeweizen You mentioned that you have experimented with having the git working directory outside the workspace and everything was snappier. Was one of those experiments carried out with your big (20,000 files) project or smaller sandbox projects? That is, can you definitively say that the 20,000 file project worked much more smoothly outside the workspace? – JamesG May 11 '12 at 01:04
  • @Bananeweizen Do you just xcopy everything to another directory, then xcopy it back to the repository before doing doing git add? – Dan Chase Feb 21 '17 at 16:27
  • @DanChase Just clone the repository, then use the import wizard directly from the git repository view. Under the hood this will create an entry in the workspace meta data, but leave all the files at the original location. You can check by opening the properties for such imported projects and their files, they are still in the git repository, not underneath the workspace directory. – Bananeweizen Feb 21 '17 at 19:24
  • 2
    This answer, and the part of the Guide from where the excerpt is, are confusing. The paragraph in the guide says "It is a good idea to keep your Repository outside of your Eclipse Workspace", i.e. _don't put the repo in the eclipse workspace_, and as reason, describes a **performance problem that is easily avoidable** using Eclipse's resource filters - they make Eclipse totally ignore the .git folders, even when workspace is refreshed, all the time. What one should definitely not do is the reverse, to place the entire eclipse workspace (with the .metadata folder) under git control. – haelix Sep 06 '18 at 17:32
  • The quoted section "This can result in performance issues" is specifically about what happens when you make the workspace *root* a git repository. This can be easily avoided by placing your repositories in a sub-directory, `./workspace/git/repo123`. The repository is still inside your workspace, just not root. The relevant quote from guide is "It is unclear whether this might cause unwanted folder traversals by Eclipse." – Annan Yearian Jun 29 '22 at 15:38
3

I am doing the same migration as the original poster and have found another thread where the same doubts are expressed on the Egit recommendation: Should I store git repository in Home or Eclipse Workspace?

@JamesG So this is your layout?

~/projectA/workspace/.metadata
~/projectA/workspace/subproj1/.project
~/projectA/workspace/subproj2/.project
~/projectA/subproj1/.git
~/projectA/subproj1/file1
~/projectA/subproj2/.git
~/projectA/subproj1/file2
Community
  • 1
  • 1
Michel
  • 1,395
  • 13
  • 14
  • Thanks for linking to that post. It made a great distinction between having multiple projects within one git repository vs one project per repository. If going for the former, then I agree that putting the repo in the workspace does not make sense, because then the .git directory is at the same level as the projects, which just feels plain wrong to me. In my case, I have the luxury of determining the repo structure, so I have decided on one repo per project, so each Eclipse project is a clone of the repo. This approach has been working well for me, even for larger projects (eg. ZF2). – JamesG Nov 27 '12 at 21:12