Getting started with Eclipse + EGit - confused - eclipse

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.

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.

Connect existing Eclipse project to existing Git repository

I have an Eclipse workspace in ~/EclipseWorkspaces/Sabia with a number of projects under Ubuntu 15.10. The source code for these projects resides in a Git repository at ~/GitRepositories/Sabia.
I can find no way to tell Eclipse in the Pydev Package Explorer that the projects use the Git Repository. If I try to use Team->Share, the system rejects the Git repository because a directory for each project exists in the repository and Eclipse is trying to move the project to the repository which already has a project directory.
I tried the suggestion by Michal Grzejszczak but unfortunately it does not work because the Git Repository does not contain complete projects, only the source trees for the projects. The Eclipse metadata is in /EclipseWorkspaces, not in the Git Repository so import projects on the Git Repository perspective does not work.
In addition when I tried to delete the projects I got the following error message:
AppFrame (One of my projects) contains resources that are not in sync with /home/jonathan/Dropbox/EclipseWorkspaces/Sabia/AppFrame. Press 'Continue' to force delete`
for half of my projects.
Unfortunately the message gives no more information and I have no idea what kind of problem might actually exist. I am not prepared to delete any flawed projects until I have corrected whatever was wrong.
How can I tell the Eclipse Pydev Package Explorer where the Git repository resides?
You need to first add this repository to Git repositories view in Eclipse. Then remove these project from workspace, but without deleting contents and then the most crucial part import them back with "Import projects..." from context menu after right clicking Working tree of the repo in Git repositories view.
That should make your projects managed by Git.

Git workflow: PDT + Egit on Eclipse workspace and Git bare repository

I'm developing a Symfony applicatoin and I'm trying to set up a Git workflow on Eclipse. The workspace (where the project files lies) are located on /home/sfprojects/testing/ and the Git repository is located on /var/git/testing.
Reading over and over all the Git resources I've could found (including "Pro Git" by Scott Chacón, and the EGit user guide (http://wiki.eclipse.org/EGit/User_Guide, among others), it's easy to understand why the Git repository and the Eclipse workspace should not share the same directory, now my big confusion is that I can not see a method to keep both things separated from each other.
Once I've created the Git repository through the wizard, all the project files are moved automatically from the Eclipse workspace to the working directory on /var/git/testing/testing/. For my big surprise, the new created Git repository became into the new project workplace on Eclipse with .git directory in the parent directory. It is not a obvious contradiction?. If I let the mouse pointer over the option "Use or create repository in parent folder of project" a very clear help tag with the following text:
When checked, this wizard will try to find or create a repository in the parent folder hierarchy of the selected projects.
Typically, newly created projects are located in the Eclipse workspace, thus repositories created this way would also end up in the Eclipse workspace.
This is not recommended for several reasons explained in the EGit user guide.
So, after some research, my logical conclusion is to create a Git bare repository and then link it to the project located in the workspace... wrong! bare repositories are not available to a Eclipse project.
I need a serious explanation on this.
Seems that I went wrong about what I thought was a contradiction in the EGit User Guide and the EGit behaviour about moving the project directory to the Git repository.
When the project files are moved as a working directory of the Git repository (with a Git metadata folder at the same level), they're still under the Eclipse control, as Eclipse workspace. But as EGit User Guide says (http://wiki.eclipse.org/EGit/User_Guide#Eclipse_Workspace_and_Repository_working_directory), the .git metadata folder should NOT be into the workspace... well that's when I was wrong, cause it is a Eclipse project/Git working folder... but it IS NOT an Eclipse workspace by any means, so the Git metadata folder is not editable, as any other source project file, just for Git (and the EGit Eclipse plugin, of course).

How to create Eclipse project with EGit clone

After spending a decade with SVN I've finally taken the plunge with Git. I have set up Git, Gitolite and GitLab on a server and have successfully added code to my local repository, committed, cloned repositories and pushed code back to repositories. So far, so good. Now enters EGit...
I have cloned a repository using the Git Repository Exploring view using the following syntax for the path:
ssh://dexter:vaultanalyser.git
(In GitLab, repositories are referred to as projects, so I assume that I am supposed to have one repository per Eclipse project? Rather than a SVN-style single parent repository that contains multiple projects?)
This imports the repository into:
/Users/mattpainter/git/vaultanalyser
I was expecting this step to automatically create an Eclipse project for me with all the source, but this isn't so. I tried fudging the target directory so it's in my workspace, but this isn't working either.
How do I get the cloned source available within Eclipse? This site implies that if you create a project with the same name as the repository, it all magically works, but this isn't the case (yes, I know the article is about Github, not GitLab, but I figured the two were close enough for the task at hand).
I've then tried creating a project in Eclipse and sharing it - but then the whole project appears as a sub-folder in the repository. If repositories are indeed analogous to projects, this isn't really what I want.
I've looked through other StackOverflow topics that look related, but I fear I'm still missing a key piece of understanding with how this is supposed to work and it's all looking remarkably convoluted thus far.
Help?
In GitLab, repositories are referred to as projects, so I assume that I am supposed to have one repository per Eclipse project?
Yes, but a GitLab "project" isn't necessarily an Eclipse one.
It doesn't have to follow an SVN structure, as illustrated in "Eclipse reference directory outside eclipse project directory but within repository".
All you need to do is to create an Eclipse project, specifying the source directory being not in the default path (Eclipse workspace), but wherever you cloned your repo (as described in "Getting started with Eclipse + EGit - confused").
That way, the eclipse project you just declared (and referenced in the Eclipse workspace) has its files (.project and .classpath) at the root of the Git repo.
And Egit can then manage that project just fine.
Or you can import it directly with Egit: "Eclipse + EGit: clone project into workspace".
As the OP nullpainter reports below:
The original issue was compounded by invalid permissions in the .git/objects folder on the server.
Running a chmod git:git -R * on the folder solved the issue
He details the right setup below.
To expand on #VonC's answer, the steps to get EGit and Eclipse to play nicely is:
Select 'Clone a Git repository' from EGit, accepting all defaults. This will create a folder in a git parent folder, somewhere outside your workspace.
Create a new Eclipse project. I'm using Java, but I assume there are similar steps for other languages. On the first dialog, untick 'Use default location' and instead select the repository folder created in step 1. Accept all defaults.
Select Team > Share Project... from your new project. Select Git, and tick the 'Use or create repository in parent folder of project'.
Now you can push your code and Eclipse dot files to your git repository from within Eclipse.
(My original issue was compounded by invalid permissions in the .git/objects folder on the server - running a chmod git:git -R * on the folder solved the issues)
I check it out with the command line - then build my projects on top of that. In fact, I end up doing most operations with command line git. EGit is useful for viewing the diffs but I find command line has more power and control. Git is mostly about giving devs lots of power and control.

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.