Importing a GitHub project into Eclipse

I've imported a GitHub project but how do I setup the project in my Eclipse project workspace?

Do I need to set the GitHub working directory(c:users) to my Eclipse working directory(c:Projects) prior to checking out the project ?

Edited :

My working directory is now c:usersprojectname.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 ?

在这里输入图像描述


As mentioned in Alain Beauvois's answer, and now (Q4 2013) better explained in

  • Eclipse for GitHub
  • EGit 3.x manual (section "Starting from existing Git Repositories")
  • Eclipse with GitHub
  • EGit tutorial
  • 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 (eg 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 (ie you have a .git directory in C:Users )

    Usually, you would clone a GitHub repo in " any directory of your choicetheGitHubRepoName ".

    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 (ie 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:usersprojectname.git

    You should have the content of that repo checked out in c:usersprojectname (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:usersprojectname , 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.


    With the last ADT, you can import Github project using Eclipse :

  • File -> Import -> Git -> Projects From Git > URI

  • Enter the Github repository url

  • Select the branch


  • I encountered the same problem, and finally found a way:

  • Add or create git repository in git view.
  • Click new java project menu, uncheck "use default location", select the git repo location, click finish.
  • Ecplise Version: Mars.2 Release (4.5.2)

    链接地址: http://www.djcxy.com/p/44378.html

    上一篇: Ant构建文件不包含javac任务

    下一篇: 将GitHub项目导入Eclipse