Egit: can several projects co-exist in one local repository - egit

I am using egit and one thing really confuses me. Suppose I have a directory /home/me/git, and I would like to put several repositories in it.
For example, the first time I share a project, say firsProject, I can designate the local repository as /home/me/git (because it is empty). And the project's root directory is /home/me/git/firstProject.
Later, when I try to share another project, say secondProject, I won't be able to use /home/me/git as its local repository because it is not empty. I end up with using /home/me/git/secondProject as the repository, and the project's root directory is then /home/me/git/secondProject/secodProject.
Is it possible to have the following structure?
/home/me/git/firstProject
/home/me/git/secondProject
How can I do it?
Note: the firstProjcet and the secondProject are two separate repositories, managed by two development teams, respectively.

What version of EGit are you using? The easiest way is this:
In the project context menu, choose Team > Share Project... and select Git
Make sure "Use or create repository in parent folder of project" is not checked
Select the /home/me/git/ repository
Leave "Path within repository" empty
Finish the wizard
Another way is this:
In the project context menu, choose Move... (or Refactor > Move...)
Create a new empty folder /home/me/git/secondProject and use that as the Location
Use Team > Sahre Project...
"Use or create repository in parent folder of project" should be checked now and you can just finish the wizard

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.

How can I create a root folder for my projects in Eclipse as recommended by EGit?

EGit User Guide suggests making a Repository working directory to store your projects, so you can add multiple projects to one repository:
How do I do this? I tried Eclipse's Create New Folder -- it only creates subfolders for projects. I tried moving the projects into a directory I created and hitting refresh -- nothing happened, and when I closed Eclipse it lost track of the .project file. I tried creating a new working set, but it didn't seem like the same thing.
Is this even a good idea?
I do it like this:
Create a directory somewhere (e.g. ~/git/myrepo)
In the console/terminal: enter the directory you just created
Create the Git repository using git init
In Eclipse, right click on your project and select Team -> Share Project...
As repository, select ~/git/myrepo/.git
Working directory is ~/git/myrepo
Click Finish
You can also try and create the repository using the "Share" dialog as well. This is something I did not try.
I believe this screenshot comes from the Git Repositories View, not Package Explorer. So you can achieve this simply by creating your repository in a folder outside of your Eclipse workspace.

Where to put Git repository in Eclipse?

If I try to put repository inside project folder
it warns it is not recommended to put git repository inside workspace.
If I try to create intermediate folder
it swears "overlaps the location of another project" at the stage of creating new project.
And if I try to create project inside workspace and repository outside, it moves the project also outside of workspace
So, the only way to use Git under Eclipse it totally abandon workspace?
If you choose the last solution you present, to deal with git and Eclipse, you will not abandon workspace, all your code will remain into your Project Workspace but you will get an additionnal folder somewhere else containing your same code, versioned, a local git repository. By choosing this solution, you can only version some parts of your project and you also avoid some possible conflicts that can arise when versioning your workspace project folder. You can also have a cleaner view of your code if you want it without eclipse metadata and do some complex git tasks on the commandline in this separate folder.

Build EGit repository outside Eclipse workspace

I use Eclipse 3.7 and EGit 1.0. If I create repositories inside my Eclipse workspace (as a sub-folder for a project) everything works fine. But obviously this is not recommended so I want to build a repository in a place elsewhere. But this does not work as expected.
I make this steps:
Create a simple Eclipse project with a text file in it (myproject).
Share -> Team -> Git
Create Button -> use c:\user as Parent Directory and mygit as Name
I leave Path within Repository empty
so Target Location is c:/user/mygit/myproject -> Finish
At this point I expect that I can manage my code via EGit. But if I choose the Team menu within the project or text file context menu I see no version control options like commit etc.
On the other hand if I delete the created repository the project is also deleted.
Does anybody know how to do this correctly? At first my goal is to build a simple single user repository.
It's quite simple (my setup: Eclipse 3.7, EGIT 1.1.0). The standard layout is to put your project inside (below) a GIT repository, so that you can have more than one Eclipse project in one repository - outside the Eclipse workspace tree.
Then, we first create the repository: In the "Git repositories" view, we create a new (non-bare) repository:
For example, in the dialog we fill:
Create a new repository
Parent directory: c:\user\gitreps\ (a directory you use to store git repositories)
Name : repo1 (your repository name)
This will create c:\user\gitreps\repo1\.git\
After this we share the existing project, which will trigger a physical move:
Take your new project, (no matter where was it created, inside or outside the workspace dir) and share it:
Project (myproj) -> RightClick -> Team -> Share -> Git
In the dialog list select the repositoy you just created (repo1) and leave the rest blank.
See that the "Current location" and "Target location"
In our example, the "Target location" should be c:\user\gitreps\repo1\myproj
When you press Finish, the project will be physically moved as we want.

How do I create a git repository over an eclipse project or vice versa?

I have a git repository that is just a directory tree (/myprogram/src/com/mycompany/test) with some source files. I wish to create an eclipse project around this repository. Both orders of create project in eclipse and git clone <url> <myprogram> from the command line give me a "folder already exists" error from whatever tool I use last. I could move the files manually to merge them, but it feels messy and I'm not 100% confident I know which files to touch.
How is this supposed to be done properly?
You could do it by selecting Import -> Existing Projects into Workspace, select the directory containing your project (the parent of myprgram), and check the checkbox next to your project (myprogram).
To have Git support in Eclipse, install eGit and then right-click your project, select Team -> Share Project -> Git, expand the triangle to select the existing repository and click Finish. This should give you Git annotations on your project.
Another option might be to just select Import -> Git -> Git Repository (after eGit is installed) and import your repository (but I've never done that with a local repository). See also the eGit user guide.
To resolve this I just ended up copying the git repository into a newly created project, but upon revisiting the issue I found a link here that suggests something slightly more elegant (but functionally similar).
After creating a new project, use Import -> Filesystem and Select All. In my case, my repository already had a proper /src/com/... directory structure which merged nicely into the one set up by the new eclipse project.