Changing Team-> Remote-> Upstream URI in Eclipse - eclipse

When I update the URI of remote Git repository for a project in the workspace, the other projects' URI is also being updated. Each project should have has its own Git repository.

For Eclipse a project is a folder on the filesystem that contains a .project resource (meta-file that describes the project, hidden by default in eclipse in the Java package explorer for example, but that can be seen in the Navigator view).
A git repository that is cloned on your file system has a root folder (in which you will find the .git folder). Your git repository probably contains several eclipse projects (in sub folders) that you have imported in your eclipse workspace.
Check your projects locations (project properties > project path) and you will see that they all reside in the same git tree.
If you change the upstream URI of your git repository, it applies to the whole repository. It cannot be applied only on a given sub folder of the tree.
So, when you right click on a project and change a Git setting (like the git URI), it applies on the whole Git repository. And as a consequence, it applies on all Eclipse projects that belong to the same git repository.
What is confusing I guess is that when you right click on a project to change its settings, you expect to change something that will only apply to that Eclipse project. This is true for most Eclipse preferences, but not for Git (because of what is explained above).

Related

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).

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'.

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?
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:
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.

Importing projects in a BitBucket repository into Eclipse

I have a BitBucket repository that contains a directory of Eclipse projects, and I am having trouble importing those projects into Eclipse.
The files contained in the repository came from a Subversion repository. They were converted to a Git repository in the usual way, associated with the BitBucket repository using "git clone ", and the BitBucket repository was populated using "git push -u origin master". The Source tab of the repository in my BitBucket account shows all of the files that were contained in the original Subversion repository. To verify that the BitBucket repository was set up right, it did a "git clone " to a different local directory and verified that the new directory had the same files as the directory from which the files were pushed to the BitBucket repository.
Within this repository is a directory containing several Eclipse projects, and I need to import them into Eclipse. To do this, I installed the EGit plugin into Eclipse, switched to Eclipse's Git Repositories view, clicked "Clone a Git repository", entered the url of my BitBucket repository, specified my Workspace directory, and check a box labeled "Import all existing projects after clone finishes". When the clone and import were finished, all of the Eclipse projects were displayed in Eclipse's Package Explorer panel.
Some of the projects display all of their contents correctly, with a project folder containing, among other things, a src folder containing nested package folders that contained Java source files.
The problem is with the other projects, which display a project folder with a greater than ('>') sign between the folder icon and the project name, and a src folder with a greater than sign between the folder icon and the string "src". This folder contains no package folders and no Java source files. Eclipse documentation and forums say that these '>' signs are displayed when a file has been changed since it was last synchronized with a repository (although they mostly talk about these '>' signs being displayed for individual files, not for folders). I tried using the Eclipse command 'Team -> Synchronize Workspace' to make sure that the folders were synchronized, but it didn't change anything. Could anyone tell me what I did wrong along the way that prevents these projects from being imported into Eclipse correctly?
Thanks,
Mike

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.