workflow: create and init multi-project repositories with EGit (Git)

This workflow is part of my DVCS blog series. If you don’t understand some steps, please read the first parts of the series.

hint: another great source are Lars Vogel’s EGit tutorials.

The goal: Workspace with n Projects in same Git Repository

It’s usual that you have to create a new repository containing some projects from inside your eclipse workspace. Here’s the workflow how to do this using EGit. If you already cloned a multi-project repository into your workspae and only want to add a new project, then start with step 2 “Add another project to the Repository“.


(Eclipse Workspace “n-projects-workspace” contains a Git Repository “n-projects-ws-repo” where two projects (“org.ekkescorner.one” and “org.ekkescorner.two“) are under version control.)

The short story:

  1. Init Repository and create first project
    1. Create the first project (at non-default location)
    2. Share the first project (create Repository at parent directory)
    3. Add ressources to Repository
    4. Commit to Repository
  2. Add another project to the Repository
    1. Create the second project(at non-default location)
    2. Share the second project (choose Repository from parent directory)
    3. Add ressources to Repository
    4. Commit to Repository
  3. You’re done: 2 projects in your workspace share same Repository

the long story:

1. Init Repository and create first project

1.1 Create the first project (at non-default location)

We create a new project, please uncheckUse default location” and enter your new location:

<workspace>/<repository>/<project>

This will create your project one level deeper as usual.

1.2 Share the first project (createRepository at parent directory)

Option-click on your project “Team -> Share Project…

Share the project as a Git project:

Now we have to configure the Git Repository: please select the project, then change the default location: remove the project name from path, because we want the repository one level higher. Please hit “Create Repository

Now the Repository is created and the project decorated as “under version control”:

Ressources not yet in your repository are marked with a question mark, the project itself is marked as “master”.

1.3 Add ressources to Repository

As next we have to add the missing ressources to the repository: “Team -> Add to Version Control…

then the Ressources are decorated as “Added, but not committed”:

Unfortunately at the moment there are two steps neccesary: add and then commit, but there’s discussion to combine this: Bugzilla 303373.

1.4 Commit to Repository

Team -> Commit…” shows this dialog, please enter a message:

Hit “Commit” and your first project is under Version Control.

2. Add another project to the Repository

2.1 Create the second project(at non-default location)

Now let’s add another project to the same repository.We create a new project, please uncheckUse default location” and enter your new location, where the repository directory is the same as described above (1.1):

<workspace>/<repository>/<project>

2.2 Share the second project (choose Repository from parent directory)

Now we have to Share this project, too – same as described under 1.2, but this time we don’t have to create a repository – we can select the existing at parent directory:

../.git

2.3 Add ressources to Repository

repeat step from 1.3

2.4 Commit to Repository

repeat step from 1.4

3. You’re done: 2 projects in your workspace share same Repository

We can’t control the repository from a Git View, but if we take a look at the file system, we can see that the repository is created successfully and contains two Eclipse projects:

To solve the same task using Mercurial /HgEclipse: here’s the workflow.

This workflow is part of my DVCS blog series – an overview of all workflows can be found here.

5 responses

  1. Thanks for posting this. It was exactly what I needed to get eGit going. Just an aside – I really thought that eGit was included in the Helios download but I had to install the plugin through Eclipse update.

  2. Thanks Ekke for describing this in detail. It was very helpful. In your step 1.2 above I notice that when you create the .git repository in parent folder of the child project, that the name of the repository includes the project name — even though the .git repository is located in the parent folder (as planned). It all works out ok, just confusing that the eGIT wizard for creating the repository does this.

  3. Thanks, two small comment though.

    1) You might add that the repository at sourceforge has to be created on beforehand using the command shell.
    2) full path to the workspace should not contain spaces. HgMercurial does not handle it correctly!

  4. Pingback: tools by Programming - Pearltrees

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s