How to point github project at Eclipse - eclipse

I have cloned a github repository and would now like to import the project into Eclipse.
The project name is 'myproject' and when cloned it is then created in my github repository :
c:\\users\\myrepo
Here are the files that were cloned :
The repository exists in a location which is different to the Eclipse workspace. How can I use this project within an Eclipse workspace ?
I'm going to answer this question as I found an answer while writing this.

Within Eclipse create a new project and set its type to the project type, in below example Scala :
Click next and on new dialog enter path to project location on local git directory :
Verify project setup is correct and click 'Finish'. The project should then be added to Eclipse and any changes made will be reflected in the git repository and so will be recognized by 'github for windows'

See http://wiki.eclipse.org/EGit/User_Guide#Starting_the_import_wizard and follow the path of Adding the clone you've already made.

Related

EGit creates separate project folder in repository

I'm struggling to create a repository for my Maven project in Eclipse. Whatever I try it turns out like so:
\ProjectA
----\.git
----\ProjectA
--------\src
--------\pom.xml
While I'd like it to be like so:
\ProjectA
----\.git
----\src
----\pom.xml
Is there any way for it to not create a separate folder under the working tree?
I'm not sure if it is the only or the best way, but creating empty repo from git directly then moving files and reimporting in Eclipse did the trick.
In case anyone needs this later:
In folder you want your repo in:
git init
Copy your sources and pom.xml and other needed files there (I also recommend creating .gitignore file at this point), then:
git add --all
git commit --m "Initial commit msg"
Then open Eclipse, delete your project and reimport it as existing Maven project directly from your repo. In my case it already recognized repo as well.
From my understanding, you are trying to create a Git repository with a single Eclipse project, located at the root of the work directory.
open the EGit Repositories view and select the Create a new Repository action
enter the name of the directory in which the repository should be created and select Finish
make sure that auto-sharing projects is enabled (enabled by default, in doubt, see Preferences > Team > Git > Projects)
open the New Java Project and enter a project name
uncheck Use default workspace location and enter the exact same path as the repository work directory (see 2.)
go to the Package Explorer, select the new project, open the context menu and select Configure > Convert to Maven Project
The detour of creating a Java project first and then converting it into a Maven project seems necessary because the New Maven Project wizard apparently always adds the Group Id to the location path.

Target location for project " " already exists, can not move project

when I am trying to share my project with git repository getting exception like this
"Target location for project " " already exists, can not move project"
Writing an answer because I tried many options suggested in many similar questions but none worked. Then I did it manually with following steps that worked, and these steps will work for any Eclipse version:
Goto the Eclipse workspace in the file system and copy the project from there and paste it in some other location in your file system. This will serve as a backup.
Goto your Eclipse and then right click on the project and click delete. You can say delete from the file system because you've already taken a backup in step1.
Goto your Git repo in the file system and paste the project folder at the location you want (may be inside another folder with .project file doesn't matter).
Then come back to your Eclipse and then File->Import -> Import from Git -> Local repo -> Select the Git local repo where you've pasted the project in step 3 and then import it as usual.
As I said earlier, this will work for any Eclipse version.
This situation will happen if you already have a Project of the same name in your local git repository. Sharing a project means steps to commit your project into your local git repository and from there it as ORIGIN will be pushed to Master (Remote). (You are creating again with a new eclipse IDE, or that project was deleted from IDE but committed to local repository in the past).
Solution is simple:
Remove the project from your local git repository.
C:\Users\username\git on windows operating system. (If this not possible then next step)
Rename the project in your IDE (Better recreate a project with same code but with new Project name) that you want to share: repeat the process of sharing on Eclipse IDE.
You may optionally want to recreate after dropping the remote repository(master), if something is already pushed from last push of project, so that everything is clean. You may visit the git repository to confirm it.
In my case this was caused by an extraneous .project and related Eclipse files at the top of the git repository folder. The files were created by Eclipse due to incorrect folder specified on Import of the other projects in the repo.

How to get src folder under project-root folder in github when staging from eclipse using egit

Current scenario :
In Eclipse when we create a project, say a PyDev project named ‘SimpleGit’, the folder structure created by eclipse will be like
EclipseWorkingDirectory/SimpleGit/src/
correct?
If we add this to git using Egit, by right clicking on the project folder SimpleGit then Team>Share, The folder structure in which repo is formed like this
Parent Folder/ SimpleGit/ .git
Parent Folder/ SimpleGit/SimpleGit/src/
And when we stage it to remote github everything will come under
Username/ SimpleGit / SimpleGit / src /
So when we look in GitHub in the root project folder (Username/ SimpleGit) we can’t see the source folder. It will be under another folder ‘SimpleGit’. How we can avoid this?
What I want is , I want to get my source forlder(src) listed under the Project Root directory, when staging from an already built project in eclipse using egit. How do I do this?
I want like this:
https://github.com/nicholasbishop/blender
Not like this:
https://github.com/afilash/SimpleGit
it cannot be done using eGit - it assumes the Eclipse project structure.
But it can be accomplished by using git itself. Just create a repository under SimpleGit folder executing 'git init'. From that point on you'd have to manage your git repository by either git itself (command line) or some other UI. SourceTree works really well for me.
It is a bit late, I know, but this method perfectly works and I hope it is useful for anyone who sees this post from now on.
The procedure is the following:
First step is creating a repository on Github (through github.com)
Move to Eclipse IDE (Git Repositories view) and click "Clone a Git Repository and add the clone to this view". Doing that the project will be somewhere located on the hard disk. Usually, it is stored in C:\Users\username\git\projectName but you are able to change it. This is our local repository.
Once done, press (in Eclipse IDE) File->Import->Projects from Git->Existing local repository(Select the one you cloned before)->Import using the new project wizard->Finish->Java->Java Project->Specify project name (just below the dialog box there is a checked checkbox that says use default location, uncheck it. Here is where you have to specify the directory you chose while cloning the repository previously).->Next->Finish
It should be enough for creating the right directory structure.

Importing with EGit clones repository but doesn't let me import project

I just started my third repository on Github. I initialized the repository on the website with a README file and tried importing it into Eclipse with Egit. Like my other projects from Github, the import dialog worked fine and the repository was cloned. In my file explorer, I can see the folder Egit created, as well as the .git folder and the README from the repository.
However, when I get to the point where Eclipse wants me to choose a wizard for project import, everything stops working. I can't import an existing project, because none exists yet. If I try to import it as a general project, it doesn't let me go further because it claims:
/path/to/my/folder overlaps the location of another project: 'gnu_magic'
This is indeed the name of the project I'm trying to import, but as I just imported it for the first time that shouldn't be a problem.
If I use the new project wizard, it doesn't let me use the same folder name as the project, claiming that the folder is not empty (which is true, but strange when I'm using the wizard to create an entirely new project). If I give the folder another name, it creates a project but the project isn't connected to the repository - I have no way of committing my changes back to Github.
Deleting the gnu_magic folder and starting all over again brings the same results.
Is there a way to remove the metadata over that specific project from Eclipse's configuration? I don't want to lose my other projects but I would like to work with Egit on that project.
Another interesting fact: If I clone the repository manually and then try to import it into Eclipse, as a project from my file system, it doesn't let me becasue the source is in the heirarchy of the destination.
Or am I missing the point here completely? I'm just surprised that I was able to clone the other repositories without any problems. Working with them over the past few days has been quite easy.
The solution was a bit strange. Here's the steps to solve it:
Clone repository using EGit
Eclipse refuses to import project, claiming it already exists. Exit import dialog.
Create new project using existing code, using cloned repository
Share project with old repository
Now the project is once again connected to the repository. Be careful with this method because if something goes wrong you might commit over your old code. This solution works with Indigo and Juno.
I'm using Eclipse 4.2 Indigo, and I've been struggling with these same problems for a while now.
If you have already cloned a repository on your machine somewhere, using EGit or whatever, you can:
1) Create a new Eclipse project.
2) File -> Import -> General -> File System Choose the cloned repository location. This will import everything, including the .git folder within the repository, into your Eclipse project in your workspace. For this it doesn't matter whether there's .project files anywhere in the imported files or not.
3) Team -> Share Project -> Git The EGit plugin should detect the .git folder within your project and suggest settings accordingly. You will have a new local repository location addded to EGit's repositories which will point to the .git folder under your project's directory.

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.