How to initialize git for a new eclipse (neon) java project



I installed a fresh copy of eclipse Neon, and created a new gradle java project in a new and shiny workspace. What is the best practice for adding git to the party?

I read that initializing git in the project directory is really a bad idea.

What is a particularly good idea then?!






The good idea is to git init a parent folder of the project different from the main workspace folder.

This is exactly what happens if you let Egit git init your project (Right click on project -> Team -> Share Project -> Git ->…) and select an external folder as repository, say c:usersjohnmy-git-repository.

You will then have two folders:

  1. c:usersjohnmy-git-repository containing the .git folder and <my-project> folder
  2. c:usersjohn<eclipse-workspace> the eclipse workspace folder, which will NOT contain your project folder (remember that eclipse workspace is just a logical container for projects, they don’t need to be physically there).

Another option is to create a folder inside the workspace, create the project as a subfolder of that folder and then git init that folder. This way:

  1. c:usersjohn<eclipse-workspace>shared-projects<my-project>

You will create the repository in the shared-projects folder (either by command line with git init or from whithin Eclipse with the wizard), which will contain the .git folder, <my-project> folder and any other project you want to share.

Remember why Eclipse suggests to keep repositories outside the workspace (

It is a good idea to keep your Repository outside of your Eclipse Workspace.

There are several reasons for this:

The new Repository will consider the complete folder structure of the Eclipse workspace as (potential) content. This can result in performance issues, for example when calculating the changes before committing (which will scan the complete .metadata folder, for example)

If your git repo is in the shared-projects folder the repository will NOT consider the complete folder structure of the Eclipse workspace as (potential) content and will NOT scan the .metadata folder since it’s outside the repo. The only contents of the repo will be your shared projects!


Facebook Comments

Post a comment