Post

Importing a GitLab project into Eclipse

Setting up a new project in eclipse currently requires a separate working directory, personally I prefer for everything to be in the workspace directory.

First go to Eclipse and create a blank project with the settings you require.

Next open a terminal / command prompt in the folder of that project (i.e. <path to workspace>\<project_name>) and execute the following commands.

1
2
3
4
5
git init
git remote add origin <PATH_TO_REPO>
git fetch
git reset origin/master <- This is only required if there are files that clash between the git repo and the local directory.
git checkout -t origin/master
  • PATH_TO_REPO - URL to clone the repository (e.g. git@github.com:angular/angular.git or the matching HTTPS url as appropriate).
  • Only do the reset if you have clashing files (given that this should be a blank project there should be none (unless you check in your project settings to which I ask “Why?”).

Ok, at this point you could edit as usual in eclipse (you might need to refresh the project to pick up the checked out files if you left eclipse open) but it doesn't know about the repo yet. So unless you want to manage the repo from command line lets get that information into eclipse.

First will be to right click on the project and go to the team sub-menu and share the project.

eclipse-team-menu

You should then be faced with a dialog similar to the following, everything should be left as is as it should automatically detect the .git folder and thus the repo in the project directory, for this dialog you specifically want the checkbox labeled “Use or create repository in parent folder of project”:

eclipse-share-project

Which after simply pressing finish to accept the team menu now opens up fully:

eclipse-project-shared-successfully

This post is licensed under CC BY 4.0 by the author.