EGit creates separate project folder in repository - eclipse

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.

Related

Cannot move project as it overlaps... Git/Eclipse

I am trying to move a project into my git repo, using Team -> Share Project -> Git, when I select the repo the error "Cannot move project x to target location...as this location overlaps with location..."
My workspace and repo are different folders (this seems to fix it for most people).
Which version of eclipse and egit plugin are you using?
For me on Kepler Service Release 2 and Egit 3.2.0 it works if I choose:
Team->Share Project->Git
and then tickbox Use or create repository in parent folder of project BUT then select the project folder . instead of the parent ..
In my case, there was a .project file inside the git repo. I just deleted it from the terminal. Then everything works perfectly. You can't access it with the GUI which is another reason why terminal is awesome!
Tried many options but they didn't work. I've posted an answer in another similar question which is a manual way to do it which will work with any Eclipse version, here is the link: https://stackoverflow.com/a/41799215/578046
I got this error when attempting to bring in a new subproject into an existing parent project in a "split" workspace i.e. the default configuration using separate workspace and git folders.
The final workaround was different from others listed:
Delete the project from within Eclipse (choose default option: DO NOT delete on filesystem)
Use the system shell move the new subproject from the Workspace location into its proper place under the parent project in the git folder structure
In Eclipse, go to the the Git Repositories view, right-click the new project folder under Working Tree, and choose "Import Projects..." to reimport the project
Re-add the project to any Working Sets it needs to be part of
I encountered the same problem, and used the following steps to solve the problem:
1、Team --> Share Project...
2、Check Use or create repository in parent folder of project,and then Check Your project...
3、Click Create Repository
4、Click Finish
I had the same problem and realized that when i cloned the git repository i selected the "import all existing Eclipse projects after clone finishes" checkbox. So i removed my repository and cloned it again without the checkbox selected. Then i had no problem sharing a new Java project into my repository (because no .project file was created on the git folder)
I had the same problem, here's how I solved it:
Open The Git Repositories View:
Window -> Show View -> Other -> Git -> Git Repositories -> Open
Then Right Click YourRepositoryName in the Git Repositories View and Click Clean...
A Popup Window will open, Tick the .project file and Click Finish
Now when you try to use Team -> Share Project -> Git it should work.
If Clean... doesn't delete the .project file, you can also manually do it by opening the repository file system in the Git Repositories View and look for the .project file then Right Click the file and Click Delete
I just went to git folder using terminal and entered the command rm .project. The problem went away.
I had a similar error once, which was caused by the name of my folder containing spaces, e.g. "Joe Doe".
Moving the project to a place where it doesn't have any space in file path solved my problem.

Eclipse - Exclude root directory from git repository?

I'm trying to setup a git repository for my Eclipse project using EGit. However, I'm having trouble excluding the root/project directory from the repository. That being, my project has the structure:
ProjectDirectory
src
war
etc
I would like the repository to contain src, war, and etc, but not contain the parent directory ProjectDirectory. That's because if I want to clone a copy of the project in my workspace, ProjectDirectory2, the repository for the second project now will try to create a second root directory, ProjectDirectory. Unfortunately, when I try to add a repository for a project using EGit, I seem to only be able to use Team > Share Project on the project folder itself and I don't seem to see anyway to exclude the root directory in the repository from within Eclipse.
Any suggestions on how to skip the top directory in the repository using EGit? I'd prefer being able to do everything from within Eclipse, but if there isn't a way, is there a way to setup the repository this way outside of git, then still be able to use the git control regularly from within git on the repository skipping the top level directory? Thank you much.
Short answer is It is POSSIBLE with EGIT + M2E
trick is when doing share project -> in the configure git repo window
making sure use or create repository in parent folder of project is ticked
and making sure click create repository button
the main aim of this is to create the .git folder in you project root
not above your project root.
Here's my solution. Though not particularly elegant - the steps are all simple, it works, and can be done in about 10 minutes:
Clone the remote git repo into your local filesystem .. e.g.: ~/git/project_repo_root
Create your eclipse project as usual .. e.g.: ~/workspace/eclipse_project_root
Delete the project from eclipse (but not filesystem!)
Open file manager and move the eclipse project you just created from ~/workspace/ root into ~/git
mv ~/workspace/eclipse_project_root ~/git/
Move the .git/ folder from the repo folder to the eclipse project root folder:
mv ~/git/project_repo_root/.git ~/git/eclipse_project_root
Using a shell go into /eclipse_project_root/ and do the usual command line commands for all files you want in the repo:
git add <abc>; .. commit; .. push
Return to Eclipse and go to Git Perspective, and click "Add an existing local Git repo to this view". Select the git repo you are working with and the view should be updated with an entry for that repo once you say ok.
Once you see the local repo in your view, you can right click it and select Import Projects
Go back to your main development perspective (Java, etc) and you should see the project there with the Git markup on the root node in package explorer view.
~~~~~
At that point, you should see the eclipse project folder you had just moved (to ~/git in the examples described here)
I realize this is more verbose than I would like my answers to be, but for this particular challenge/solution .. I don't know of a more straightforward way to do it.
And as for the post above that describes you should always include the eclipse project root directory .. the reality is some projects/clients/etc require that the git repo not contain the root folder. So a solution like this is necessary sometimes
You should commit the project root for multiple reasons:
If you commit only sub directories of your project, you will miss files and folders which are hidden below the project root (e.g. the .settings directory and others). Those need to be committed also, otherwise your project is going to miss information and may not lead to the same results on another machine.
Your wish of trying to clone the same repository a second time in the same workspace sounds very much like you should re-read about git branches. In git, switching between branches is done after a blinking of the eye, so branches should be used when working on different features, versions or otherwise different editions of your project.
The Eclipse project name and the underlying folder name on disk do not need to be the same (watch out for the checkbox "use default location" when creating a new project). So you can checkout a second clone of the project with a different name.
If you later add more projects to your workspace (e.g. a test project), you cannot easily share them into the same git repository, as the content of those additional projects would mix up with the sub directories of the first project in the repository.
If you have maven project you would typical like to create a repository without the project folder created by egit. For my experience this is not possible with the egit plugin.
But it can be easily done from the git command line.
First move your existing eclipse/maven project from your eclipse workspace into your git folder (this is what also the egit plugin did):
mv myproject ~/git/
next create a new git repository
cd ~/git/myproject
git init
Now create a .gitignore file and place it into your new repository folder (~/git/myproject/.gitignore). This is an example for a .gitignore file:
# ignore all bin directories
# matches "bin" in any subfolder
bin/
# ignore all target directories
target/
# ignore all files ending with ~
*~
# ignore eclipse directories and project files
.settings/
.project
.classpath
Finally initalize your new repository with the content of your project
git add *
git commit -m "My initial commit message"
Thats it.
Now you can restart your eclipse and reimport the project from your new git repository.
Go into your eclipse egit repository view and coose 'import exisiting project'.

Import an existing Git project into Eclipse without a .project file

I've forked and cloned a project to the local machine from GitHub using the terminal and am trying to import it into Eclipse.
The problem is the clone from GitHub doesn't have a .project file, so when I go import -> projects from Git, I can only import as a general project. How can I import the project to Eclipse without doing git init? Most of the solutions I saw have .project already there when they cloned it from Git.
Create a new java project, Untick "Use default location" and browse the git project path by clicking browse button. It works for me. I have just imported a Git, netbeans project into Eclipse through this simple method.
After a while I got it working as expected...
Basically the wizard is broken. This is what worked for me (eclipse 4.2.2):
You may use the wizard to import the git repository to your workspace.
After that you need to close the wizard and open the git Repositories view. (Window->Show View->Others->Git->Git repositories)
Right click on the repo you've just imported and select "Import Projects..."
I've imported a general project (it was SQL code only) and this time it worked as expected (The screen doesn't allow you to change the project name nor directory, which makes sense at this point.)
Those are the same steps performed by the wizard, but apparently it doesn't get the information about the project being already deployed at the workspace, so you get the option to change those values and it complains about the project already existing there.
You should create a new project in Eclipse and specify that the project be located in the existing directory.
Choose "Create project from existing source" in the wizard:
I use eclipse 3.7 ( indigo ) and I find this great solution:
1) click on: Navigate -> Show In -> Project Explorer
2) from Filesystem folder, find and select the folder where the project is contained
3) right chick on folder, and select Promote to Project
Do this:
File > Import > General > Existing Projects Into Workspace
then:
select root directory: select the path in you pc where the project is
if you want to to copy the existing project in a new project into your workspace, check the field copy projects into workspace, otherwise don't check it and continue to work directly into the existing project

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.

Getting started with Eclipse + EGit - confused

I am used to using Eclipse with SVN and CVS.
Now I want to use GIT via EGIT.
The goal is to have a local repository, not in the eclipse work-space, that my changes go into. That way, I can make changes, commit them, and have a repository with the changes that I can back up (at least, that's how it works in SVN).
Following the user's guide, I find it creates the repository within my Eclipse project in the workspace, which is recommended against. What am I missing?
Steps:
Create a Java project in Eclipse (Test)
On Project right click->Team->Share Project->Git
...Next - shows "Configure Git Repository" Panel
...the only repository it will let me create is inside the project.
Huh?
You can create multiple projects under one repo in EGit, see http://wiki.eclipse.org/EGit/User_Guide#Creating_a_Git_Repository_for_multiple_Projects In that case, EGit will do it automatically.
You can also use the Git Repository view to create an empty git repo outside of the workspace. See http://wiki.eclipse.org/EGit/User_Guide#Creating_a_Repository After that, you can create new java projects and specify the external git repo subdirectory as their location.
Since:
you can create a java project outside of the workspace
(see option "create project form existing source": the .project and .classpath will be created in the parent directory of the directory you will select as containing the sources)
Egit will create the .git where the .project and .classpath are created
you will have a repo outside of the Eclipse workspace.