score:107

Accepted answer

as mentioned in alain beauvois's answer, and now (q4 2013) better explained in

copy the url from github and select in eclipse from the menu the

file → import → git → projects from git

http://wiki.eclipse.org/images/5/5a/egit-0.9-import-projects-select-repository.png


if the git repo isn't cloned yet:

in> order to checkout a remote project, you will have to clone its repository first.
open the eclipse import wizard (e.g. file => import), select git => projects from git and click next.
select “uri” and click next.
now you will have to enter the repository’s location and connection data. entering the uri will automatically fill some fields. complete any other required fields and hit next. if you use github, you can copy the uri from the web page.

select all branches you wish to clone and hit next again.

hit the clone… button to open another wizard for cloning git repositories.

http://eclipsesource.com/blogs/wp-content/uploads/2012/12/14-282x300.png


original answer (july 2011)

first, if your "working directory" is c:\users, that is odd, since it would mean you have cloned the github repo directly within c:\users (i.e. you have a .git directory in c:\users)

usually, you would clone a github repo in "any directory of your choice\thegithubreponame".

as described in the egit user manual page:

in any case (unless you create a "bare" repository, but that's not discussed here), the new repository is essentially a folder on the local hard disk which contains the "working directory" and the metadata folder.
the metadata folder is a dedicated child folder named ".git" and often referred to as ".git-folder". it contains the actual repository (i.e. the commits, the references, the logs and such).

the metadata folder is totally transparent to the git client, while the working directory is used to expose the currently checked out repository content as files for tools and editors.

typically, if these files are to be used in eclipse, they must be imported into the eclipse workspace in one way or another. in order to do so, the easiest way would be to check in .project files from which the "import existing projects" wizard can create the projects easily. thus in most cases, the structure of a repository containing eclipse projects would look similar to something like this:

see also the using egit with github section.


my working directory is now c:\users\projectname\.git

you should have the content of that repo checked out in c:\users\projectname (in other words, you should have more than just the .git).

so then i try to import the project using the eclipse "import" option.
when i try to import selecting the option "use the new projects wizard", the source code is not imported.

that is normal.

if i import selecting the option "import as general project" the source code is imported but the created project created by eclipse is not a java project.

again normal.

when selecting the option "use the new projects wizard" and creating a new java project using the wizard should'nt the code be automatically imported ?

no, that would only create an empty project.
if that project is created in c:\users\projectname, you can then declare the eisting source directory in that project.
since it is defined in the same working directory than the git repo, that project should then appear as "versioned".

you could also use the "import existing project" option, if your github repo had versioned the .project and .classpath file, but that may not be the case here.

score:-1

when the local git projects are cloned in eclipse and are viewable in git perspective but not in package explorer (workspace), the following steps worked for me:

  • select the repository in git perspective
  • right click and select import projects

score:0

it can be done in two ways:

1.use clone git

2.you can set it up manually by rearranging folders given in it. make a two separate folder 'src' and 'res' and place appropriate classes and xml file given by library. and then import project from eclipse and make it as library, that's it.

score:0

i think you need to create a branch before you can import into your local eclipse, otherwise, there is an error leading to incapable of importing repository from github or bitbucket.

score:4

using the command line is an option, and would remove the need for an eclipse plugin. first, create a directory to hold the project.

mkdir mygitrepo
cd mygitrepo

clone the desired repository in the directory you just created.

git clone https://github.com/jonashelming/gittutorial.git

then open eclipse and select the directory you created (mygitrepo) as the eclipse workspace.

don't worry that the project explorer is empty, eclipse can't recognize the source files yet.

lastly, create a new java project with the exact same name as the project you pulled. in this case, it was 'gittutorial'.

file -> new -> java project

at this point, the project's sub directories should contain the files pulled from github. take a look at the following post in my blog for a more detailed explanation.

http://brianredd.com/application/pull-java-project-from-github

score:8

unanswered core problem persists:

my working directory is now c:\users\projectname.git so then i try to import the project using the eclipse "import" option. when i try to import selecting the option "use the new projects wizard" the source code is not imported, if i import selecting the option "import as general project" the source code is imported but the created project created by eclipse is not a java project. when selecting the option "use the new projects wizard" and creating a new java project using the wizard should'nt the code be automatically imported ?

yes it should.

it's a bug. reported here.

here is a workaround:

  • import as general project

  • notice the imported data is no valid eclipse project (no build path available)

  • open the .project xml file in the project folder in eclipse. if you can't see this file, see how can i get eclipse to show .* files?.

  • go to source tab

  • search for <natures></natures> and change it to <natures><nature>org.eclipse.jdt.core.javanature</nature></natures> and save the file

    (idea comes from here)

  • right click the src folder, go to build path... and click use as source folder

after that, you should be able to run & debug the project, and also use team actions via right-click in the package explorer.

if you still have troubles running the project (something like "main class not found"), make sure the <buildspec> inside the .project file is set (as described here):

<buildspec>
    <buildcommand>
        <name>org.eclipse.jdt.core.javabuilder</name>
        <arguments>
        </arguments>
    </buildcommand>
</buildspec>

score:9

i encountered the same problem, and finally found a way:

  1. add or create git repository in git view.
  2. click new java project menu, uncheck "use default location", select the git repo location, click finish.

ecplise version: mars.2 release (4.5.2)

score:22

with the last adt, you can import github project using eclipse :

  1. file -> import -> git -> projects from git > uri

  2. enter the github repository url

  3. select the branch


Related Query

More Query from same tag