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?
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.
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.
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:
Move the files within the project to the root of the remote repository / Create the remote repository if this is a new project.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With