Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Egit adding Eclipse project folder to git repository

I've created a new empty git repository on BitBucket and now I want to link it to Eclipse.

I added the repo to the "Git Repositories" view and created a new project with the same name.

I select "Team -> Share Project" then commit and push upstream.

Now my repository has folder structure /my-long-project-name/My Long Project Name/

Is there any way to make the project folder the root of the git repository?

like image 444
EddyR Avatar asked Mar 15 '13 05:03

EddyR


People also ask

Can I add folder to Git repository?

GitHub does not allow you to add blank folders to your Git repository. A folder must contain a file before you can add it to a repository. If you want to create a new folder, create it first and then add a placeholder file into that folder. Then, add the new folder and file to your Git repo.


1 Answers

From the EGit Eclipse Wiki page:

It is probably not a good idea to make a project the root folder of your Repository

The reason is that you will never be able to add another project to this Repository, as the .project file will occupy the root folder; you could still add projects as sub-folders, but this kind of project nesting is known to cause lots of problems all over the place. In order to add another project, you would have to move the project to a sub-folder in the Repository and add the second project as another sub-folder before you could commit this change.

I know this is not a solution, but at least this gives a valid reason for having to endure the additional folder with the same name.


The (not recommended !) workaround

Create/modify the remote repository, then clone into a new local project:

If you haven't started developing yet or can afford to move the contents of the duplicate sub-folder (in your case, "My Long Project Name") to the root of the git repository, you can avoid ending up with twice the same folder, by going the other way around:

  1. Move the files within the project to the root of the remote repository / Create the remote repository if this is a new project.

  2. In the "Git Repositories" view in Eclipse, find the "Clone a Git repository and add the clone to this view". Follow the steps to clone your repository from your URI to a local folder.

  3. In the same view, right-click the repository in the list and choose "Import Projects..."

    • If you have a .project file in the root folder, i.e. the files where already part of an Eclipse project, choose "Import existing projects" and choose the root folder, then watch Eclipse do its magic.

    • If this is a new project (or the files on the origin are not an eclipse project), choose "Import as general project", then modify the project type in Eclipse afterwards if you need a specific project type.

Disclaimer: I personally decided not to use this workaround and to stick with the EGit recommandations.

like image 83
edsioufi Avatar answered Oct 27 '22 10:10

edsioufi