Eclipse Egit will not import repo in workspace - eclipse

I am trying to import an existing git repository as an eclipse project. The repository is stored in the location ~/src/repo_dir, and ~/src/ is my eclipse workspace directory.
If I use the sequence of menu operations:
File --> Import --> Git --> Projects from Git --> Local --> (Select my repo)
--> "Import as General Project"
I get the error:
/Users/me/src/repo_dir overlaps the location of another project: 'repo_dir'
and I can't import the project. It seems to be because Egit does not want the original repo that is being imported to already be in the workspace. However, if I then move the repo_dir out of the workspace directory ~/src/, and then import the project via the method above, it doesn't copy the contents to the workspace directory, so now my files live somewhere else, which is undesirable. The only workaround that I have found is to move the repo out of ~/src, import it, delete the resulting project, move the repo back into ~/src, and then import it with git as an 'Existing project.' Does anyone know of a cleaner way to handle this?

There are two different issues here:
Git handles a selected folder in your computer as a repository - and also stores some git-related metadata in it.
Eclipse handles a selected folder in your computer as your workspace. It stores that Eclipse configuration files (not meant to be shared), and even worse, it expects a single-level folder hierarchy for projects.
This means, putting a Git repository inside the workspace might cause a lot of unwanted issues - so I do not recommend this way (even if by some hack it is workable). However, if you want to organize all stuff related to an Eclipse workspace, you could create a folder structure as this:
eclipse-stuff
workspace
git
git-repo1
git-repo2
The workspace folder is given to Eclipse as the workspace folder, while git-repo1 and git-repo2 are your Git repositories.
On the other hand, I like to put all my git repositories into a common folder, regardless of the Eclipse workspace I use them in, but if you want to organize contents, this might not be enough for you.

Had this problem with Eclipse Kepler.
End up with installing Eclipse Mars and import the new project in another workspace.(Luna will also work fine)
If you need to work on current projects and set up environment for the coming one...

Related

Some or all projects can not be imported because they already exist in the workspace error in Eclipse" [duplicate]

I just added repository A to my Git perspective in Eclipse (which also instanced a local Git repository under some path) and can now see the working tree. Now how do I work on the files in the package explorer?
From what I've seen I have to use "import projects" - what does this do? My Eclipse workspace seems to be empty, while made changes will all display in the git repository.
Also, how do I work with multiple repositories and how do I switch between them? When I try to "import projects" from repository B I get the message that Some or all projects cannot be imported because they already exist in the workspace
The issue here is that Eclipse maintains its own file system representation that includes projects. This was required historically to support incremental compilers, even if the file system is not capable of sending notifications.
The Import projects option you have seen relates to importing projects from a git repository into the Eclipse file system; adding the repository to Eclipse allows Eclipse to know about the repository, and execute repository operations (e.g. fetch, commit, push).
About why doesn't the project import work, the Eclipse file system contains a set of top-level projects (each can be either in the workspace folder or somewhere on the disk, e.g. in a git repository); however, it is not possible to have two projects with the same name in the same workspace.
If you want to open the "same" project from two repositories (e.g. two development branches), you have to rename them not to have a common name. This name is stored in a .project file in the project root (or if none exists, it will be derived); you can use a refactor operation to change the project names. After that, you can import both projects into your Eclipse workspace.

Correct way to import projects in EGit?

I just added repository A to my Git perspective in Eclipse (which also instanced a local Git repository under some path) and can now see the working tree. Now how do I work on the files in the package explorer?
From what I've seen I have to use "import projects" - what does this do? My Eclipse workspace seems to be empty, while made changes will all display in the git repository.
Also, how do I work with multiple repositories and how do I switch between them? When I try to "import projects" from repository B I get the message that Some or all projects cannot be imported because they already exist in the workspace
The issue here is that Eclipse maintains its own file system representation that includes projects. This was required historically to support incremental compilers, even if the file system is not capable of sending notifications.
The Import projects option you have seen relates to importing projects from a git repository into the Eclipse file system; adding the repository to Eclipse allows Eclipse to know about the repository, and execute repository operations (e.g. fetch, commit, push).
About why doesn't the project import work, the Eclipse file system contains a set of top-level projects (each can be either in the workspace folder or somewhere on the disk, e.g. in a git repository); however, it is not possible to have two projects with the same name in the same workspace.
If you want to open the "same" project from two repositories (e.g. two development branches), you have to rename them not to have a common name. This name is stored in a .project file in the project root (or if none exists, it will be derived); you can use a refactor operation to change the project names. After that, you can import both projects into your Eclipse workspace.

Why can't I use my workspace if its a Git repo with eclipse

I have a git repo that has a lot of test scripts in it. I started by setting this repo as my "workspace" in eclipse so I could make changes directly with eclipse and then just push them up to bitbucket once they are done.
Eclipse wont let me do this, I cant see anything in my work space and when I try to import the local repo to the workspace it tells me "Can't import project MavenTest from an existing workspace folder"
This doesn't make sense to me since I would have to make a separate workspace from my repo and then do the work into the workspace and manually copy it to the local repo and then push it up to bitbucket. Also pulling everything down will be a pain too since I'll have to copy any changes to my workspace. I defeats the whole purpose of version control.
Can someone please explain to me what I am doing wrong? I just want to work, push and pull all in the same directory.
Eclipse expects everything at the top level of its workspace directory to be a project, or otherwise content written by a plug-in through Eclipse's APIs. Any other content in the repository will be unusable and not importable as its location already overlaps the location of the workspace.
I would have to make a separate workspace from my repo and then do the work into the workspace and manually copy it to the local repo and then push it up to bitbucket.
Wrong. You're under the misconception that everything shown in the workspace has to physically live under the workspace directory, which is very untrue. They don't have to be there, they don't even have to be physical files.
Typically you will make Eclipse aware of the local clone using its Git Repositories View, and then use the view's context menus to import content from the repository's working directory as projects in the workspace (or using a Maven wizard provided through M2E). This import will not duplicate anything. You will still have one canonical location for your sources: your repository.
https://wiki.eclipse.org/EGit/User_Guide#Creating_Repositories

spliting git repository from eclipse project - egit

I'm more or less a git newbie, trying to get a good Setup to work in Eclipse with egit. I'm running Kepler with latest updates.
Originally I Setup the structure inside the Workspace Directory.
+Workspace/.git
+Workspace/TheProject
Using this Setup (admittedly with Juno) commits were taking forever. For this and other reasons I'd like to move git outside the Workspace Directory, outside eclipse in a parallel Directory.
+OtherDirectory/.git
+Workspace/TheProject
But I'm not getting very far. There seems to be no easy way to split the EXISTING git to another Location without having the Project move there too(!?)
I've tried e.g. Cloning the existing git (in the git repository perspective) and having it Import the Project in the same move.
I've tried just Cloning the existing git, without selection of "Import Project" at the same time.
Then I right clicked the cloned repository and went through the Import Existing Project dialog. I don't get a Chance to say where the Project should be loaded to.
In both cases the Project Ends up in the same Directory as the .git Directory (now outside the Workspace)
+OtherDirectory/.git
+OtherDirectory/TheProject
and not as I wish - to have the Project in the Workspace Directory.
This must be possible (?), but how?
Simply copy the .classpath and .project from Workspace/TheProject or OtherDirectory/TheProject, to otherDirectory (where the .git folder is).
Then import your project into the workspace, as in "Eclipse - Import an existing project?"
Everything will remain in OtherDirectory/ (outside your Eclipse workspace folder), but will be visible in your Eclipse workspace.

Eclipse + EGit: clone project into workspace

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.
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:
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.
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.
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.
Steps to have git project in workspace (with egit):
On GIT perspective choose "Clone a Git Repository and add it to this view"
As a destination choose folder inside a workspace (for example ".../workspace/myproject")
Wait until cloned
File -> New -> Project
General -> project
As a project name type name of a folder in workspace where project has been cloned (for example "myproject")
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.
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.