How to import GitHub and Bitbucket repositories into Eclipse Mars?

51,647

Solution 1

First you need to clone the (git) repository in Eclipse.

Steps to clone git repo in Eclipse

  • Go to GitHub, or BitBucket, and copy the URL of the repo to clone
  • In Eclipse, Open the perspective Git
  • Use the shortcut icon Clone a Git Repository ... (the icons are shown on the view Git Repositories)
  • The dialog Clone Git Repository opens, with the page Source Git Repository
  • (The url of the git repo, should already be filled in, at the field uri)

TIP: The field uri can not be edited. Use the other field, like Host, repository Path, etc to correct the url if required.

  • Press the button Next
  • The page Branch Selection opens
  • All branches from the remote git repository are now shown
  • (Mark the branches you like to clone, by default all branches are checked for cloning)
  • Press the button Next
  • The page Local Destination opens
  • Make sure you select the correct location, where the local clone of the repository should go (something like /home/<user>/git)

TIP: Make sure that you do NOT clone the git repository inside the Eclipse workspace directory!

  • Select from the drop-down Initial branch the branch you like to start working on. (Default is the master branch. Can also easily be changed later.)
  • Press the button Finish, to start the cloning job.

After successful cloning of the git repository, the project(s) in the git repository can be imported into Eclipse as (Eclipse) projects.

Import project in Eclipse

Open the Eclipse perspective Java

Maven Project

This will import Maven project(s) (based on pom.xml file(s)) as Eclipse project(s)

  • From the view Package Explorer select right mouse button menu: Import... or use the Eclipse menu: File -> Import...
  • The dialog Import opens, with the page Select
  • Select from the tree: Maven -> Existing Maven Projects
  • Press the button Next
  • The page Maven Project opens
  • Choose the Root Directory to scan for Maven projects. Use the button Browse, to go to the just cloned git repository (/home/<user>/git)
  • Once the location is selected, the Projects should appear, in the form of located pom.xml files.
  • (Normally all projects are selected. At a 2nd import, some may be grayed out, as they already exist in the Eclipse Package Explorer, as project)
  • Press the button Finish to import the Maven project as Eclipse projects

Eclipse

In case the git projects do contain the typical Eclipse configuration files / directory (like: .project, .classpath, .settings), then they can be imported as Standard Eclipse projects

  • From the view Package Explorer select right mouse button menu: Import... or use the Eclipse menu: File -> Import...
  • The dialog Import opens, with the page Select
  • Select from the tree: General -> Existing Projects into Workspace
  • Press the button Next
  • Choose the Select Root Directory to scan for Eclipse projects. Use the button Browse, to go to the just cloned git repository (/home/<user>/git)
  • (Select from the Options the check box Search for nested projects in case the imported project contains nested Eclipse projects)
  • (Normally all projects are selected. At a 2nd import, some may be grayed out, as they already exist in the Eclipse Package Explorer, as project)
  • Press the button Finish to import the Maven project as Eclipse projects

Solution 2

Prerequisites GitHub/Bitbucket:

Get an GitHub/Bitbucket account.

  • List item
  • Create a new repository in GitHub/Bitbucket
  • Make a branch of your "master" in your new repository, it is good practice not to do changes in directly in the "master" but merging the changes from a branch.

Prerequisites on your computer:

  • Install Eclipse Mars

Setup the git project in Eclipse

  • Open perspective "Resource"

    • Menu: Window / Perspective / Open Perspective / Other and choose "Resource"
  • Import your GitHub/Bitbucket branch

    • Menu: File / Import, a wizard opens
    • Wizard (Select): Under "Git" choose "Project from Git" and press "Next"
    • Wizard (Select Repository Source): Choose "Clone URI" and press "Next"
    • Wizard (Source Git Repository): At top "Location / URI:" paste in your GitHub/Bitbucket Url. (In GitHub/Bitbucket site right click your repository link and choose copy link address)
    • Under Authentication fill in your GitHub/Bitbucket user and password and press "Next"

    • Wizard (Branch Selection): Only check your branch, deselect all others and press "Next"

    • Wizard (Local Destination): Choose a folder where you like to keep your git project, don't put it in your workspace folder and press "Next".

    • Wizard (Select a wizard to use for importing projects): Select "Import as general project" and press "Next"

    • Wizard (Import projects): Press "Finish"

The project should now be visible in the "Project Explorer"

Create the ".gitignore" file

This is importent or your code will be mixed with Eclipse files

In "Project Explorer" right click your project folder an then New / File enter ".gitignore" at the "File Name" prompt and press "Finish"

Paste the following in to the file.

# eclipse specific git ignore
*.pydevproject
.project
.metadata
bin/**
tmp/**
tmp/**/*
*.tmp
*.bak
*.swp
*~.nib
local.properties
.classpath
.settings/
.loadpath

Finally keep your Eclipse project in sync with GitHub/Bitbucket

  • Menu: Window / Perspective / Open Perspective / Other and choose "Git"

  • In the "Git Perspective" drag files from "Unstaged Changes" to "Staged Changes" Enter a "Commit Message" describing your code changes and finally press "Commit and Push"

Share:
51,647
Peter Korinek TellusTalk
Author by

Peter Korinek TellusTalk

Working as a programmer at TellusTalk AB. Currently Python in a Google App Engine environment, Html, JavaScript, JQuery, CSS, Node, MySql. TellusTalk provides corporate messaging services like Email, SMS, Text, Link-SMS, MMS and more. http://www.tellustalk.com

Updated on October 14, 2020

Comments

  • Peter Korinek TellusTalk
    Peter Korinek TellusTalk over 3 years

    I installed Eclipse Mars enabled the Git perspective and imported a repository. It looks fine, but Eclipse is not behaving normal I can't create new files and search is not finding anything outside the file I'm in. What is the proper way to import repositories/projects from GitHub, Bitbucket and other Git Hosts?