64

I'm a little confused about how EGit workes.

I have an existing git repository on Github and want to clone it into my workspace. My goal is to have the local repository directly stored inside my workspace-folder but I don't get it working with EGit.

When I want to clone the github repo with EGit, I have to choose a directory as destination. The suggested directory is in my homedir (not in my workspace). When I choose this directory I can see the project in Eclipse but it is not stored in my workspace-folder. Instead it is stored in my home dir.

When I choose a directory directly inside my workspace, later when it comes to import the project it says that there is already a directory with this name.

I don't know how to solve this. I thought this would be a common scenario. In the past I have used hgEclipse (Mercurial) and it was working exactly the way I thought it should be so I'm confused EGit doesn't. Maybe I misunderstood something.

Probably this is important to know: In the github repository there are no .project or .settings files from eclipse. I have them on my .gitignore and so in the import-dialog I have to choose "Import as General Project" and not "Import Existing Projects". But I think this shouldn't matter?

I hope someone can help me or explain me why the EGit plugin doesn't clone the repository directly into the workspace by default.

My Eclipseversion is 3.6, I have installed EGit over the markedplace.

6 Answers 6

17

As mentioned in this EGit tutorial, the destination directory you mention when importing (cloning) a Git repo is any directory you want, in which the .git will be created:

Import Git Repository

You don't have to select the workspace itself (at least, you should select the workspace/myproject subdirectory, in order to not make the all Eclipse workspace a Git repo.

And you can select any other directory outside the workspace: the Eclipse workspace should only contain meta-data about Eclipse projects and settings.
When declaring a new project, you will be able to select the project directory, making that directory the parent for .classpath and .project.
Your workspace will list that new project, even though it lives outside the workspace.

4
  • 7
    Why should the Eclipse workspace only contain meta-data? When I have the projects inside my workspace It's easy to make a backup and I always know where my files are located. Jun 18, 2011 at 13:52
  • 2
    @lastard: I keep sources well separated from any IDE, that way, I can change IDE or change workspace within an IDE without having to worry about file migration. That being said, if you select a subdirectory within your workspace, a .git should be created within it and the git repo should be checked out in it. In other word, if you want your project within your workspace, that should be possible.
    – VonC
    Jun 18, 2011 at 14:05
  • Thanks for the answer. Being independent from the IDE is the reason why I don't commit the Eclipse specific .project files to github but on my local computer I like to have all projects within my workspace. Jun 18, 2011 at 15:08
  • @lestard: I would still commit .project and .classpath ;) See stackoverflow.com/questions/5718318/… and stackoverflow.com/questions/2818239/…
    – VonC
    Jun 18, 2011 at 17:37
3

To import a project from GitHub you should use the Import Git Repository as New Project dialogue (right click -> Import -> Git -> Git Repository as New Project). This way you can select the destination of the clone repository, including the Workspace.

2

If you want to edit the sources in the IDE and also want the changes to be reflected in the Git repository, delete the original source file in the project and link the source file in the git repo to the project. That way, you can directly make changes to the git repo and you can commit them when needed. Be careful not to delete the files when deleting the project in the IDE though.

1

Steps to have git project in workspace (with egit):

  1. On GIT perspective choose "Clone a Git Repository and add it to this view"
  2. As a destination choose folder inside a workspace (for example ".../workspace/myproject")
  3. Wait until cloned
  4. File -> New -> Project
  5. General -> project
  6. As a project name type name of a folder in workspace where project has been cloned (for example "myproject")
0

Nope. There's no way to get this to work. You can't use egit to checkout a git project into the workspace and if you check it out elsewhere and try to copy it into the workspace, you will lose your connection to the remote repository. If you want VCS that works, use svn or mercurial.

2
  • This is 1) not remotely true, and 2) if it were true, it would represent a problem with Eclipse's git support, not with git itself. So I'm not sure why you're promoting alternative VCSs.
    – Brad Mace
    May 22, 2019 at 13:24
  • That comment was written in 2011. It's 2019.
    – jcfolsom
    May 24, 2019 at 0:45
0

In the "Configure Local Storage Location" dialog, choose .../workspace/projectname.

Then in the next dialog, we get the wizard selection menu. Normally you should select "Import existing project". (But see below).

Finally, there is the "Import Projects" dialog. For various unexplained reasons, sometimes this dialog is empty and won't let you finish. In that case, you need to cancel, and then outside of Eclipse completely delete the working directory that was cloned into, and then start again.

But if there is the project there, press finish. If it complains about the project already existing, go back to the wizard menu and change it to use a wizard. Select a Java wizard and then finish. Often this will work, but only if you first got the "Import Projects" menu to recognize the project in the first place.

It may take several attempts to get this to work! But once it is set up, it works fine.

So, in summary: is is possible to get EGit to use the default project location for the git clone, but in my experience it may inexplicably require several attempts.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.