How do I add an Eclipse java project with EGit to Github? - eclipse

I have created a repository on Github and have the project in my Eclipse. I also have the Egit plugin and Github plugin. I've looked all over the internet for help on this, but I at last must turn to the Stack Overflow community.
How do I add my java project from eclipse into my repo on Github?

There are a few tutorials out here on how to import projects from git into eclipse.
Though, you can follow these steps:-
Choose the "Git" Perspective, from Window->Perspective->Open Perspective->Other, and then search for Git and select it. This opens the Git repositories view.
From the "Git Repositories" view , choose the option which says "Clone a git repository and add the clone to this view."
Follow the wizard, enter all the details.
Choose the branches you want to import.
Choose the local directory, select clone the sub-modules.
You can choose to import all existing projects by checking the box against "Import all existing eclipse projects", now or you can selectively import projects later. Hit finish.
The git repositories view will now show your repository.
Now you will need to import projects from this repository, only if you havent selected the "Import all existing eclipse projects" box before.
Right click on your repository from the Git Repositories view. Select "Import Projects" option.
Check the radio option, "Import existing Eclipse projects", select the project from your working directory. Click next and then hit Finish.
The Project Explorer should now be showing your project listed there and the name of the branch in square brackets.
Make changes, add files, edit files, once you are ready to make your first commit. Right click on your project under Project Explorer, select Team->Pull.
If this is your first commit, it will say Nothing to update - everything up to date. Hit Ok. Otherwise, it will download the changes, if there are merge conflicts , it will show you those. There are other tutorials which will guide you through dealing with merge conflicts.
Right Click again on your project, select Team->Commit.
This opens a Commit Changes window, leave a meaningful commit message.
Select Commit and push.It should ask you for your username and password, you can check the box, which says store these.
Should show Pushed to origin with Message Details. Hit ok, and you are done with your first commit.

Select a project. Right click, Team->Share. Select the Git provider. Follow the wizard.

Related

How to select repository for staging view in Eclipse Luna 4.4?

I'm not able to find a solution to a documented bug in Eclipse (Luna 4.4). I've cloned a git repository from Github into my eclipse workspace view and imported the associated Maven project into my project space. When I then display the staging view in Eclipse, it appears, but says "No Repository Selected" up top. I'm therefore unable to drag any changed files into the staging area and commit them. How do I associate my cloned repository with the staging view?
Try enabling linking between the Git Staging view and other views. You do so by pushing the "Link with Editor and Selection" button on the top right of the view, to the right of the "Refresh" button.
In the top image, the view is not linked.
In the bottom image, the view is linked and the button appears "pushed"
"Enabling linking between the Git Staging view and other views" didn't help in my case. I also tried deleting branch and checking out again. Nothing worked.
What I did was:
Right click on any of the modified file -> Team -> Commit.
Somehow it worked and I could see all modified files in unstaged changes.
I had the same issue. This is what worked for me
- Under the 'Package Explorer' Right click on the your project
-> Team -->Share Projects...
-> Then in the list of projects, select your project
* Seems weird, but sharing back to itself resolved this issue for me
Good Lucks
click on git icon,
select the repositorie you want to use
right clik to show the menu
then select "show in"
then select "git staging"
Maybe you are missing one step. If you have a local repository already:
1. On "Quick Access" of your Eclipse search Git repository
2. Select Team option (Right click on project -> Team) and select Share Project, mark Use or create...and select .git directory of your project cloned.
3. Select Team option and now select Add Index
4. Select Team option and now select Commit, you will see Git View now has your project with the correct branch.

Share eclipse java project on github

I am trying to push a eclipse java project to github. That is how I am trying to do it:
In the "git repositories" view, I added my repository, I just created on github:
https://github.com/xxx/SpringTest.git
Now I want to share my project to that git repository. I do that by right click on the project -> team -> share project...
I select my repository, but the next button is greyed out. What am I doing wrong here?
Edit: "Next" and "Finish" is greyed out:
Following the Egit manual, the Next button is always greyed out at this point:
You would need to click on Finish in order to complete the process.
You just need to be sure you have a git repo already initialized where your project is.

How do I rename my local git repository

I've renamed my remote repository and created a new local repository from it. How do I change it within EGit in Eclipse?
Previous answer list below also has issues. The only solution appears to be:
Backup .project, etc. files
Delete existing project
Import existing local git repository as a "general project"
Put backed up files into the new project
Restart Eclipse
Rename, per se, is not the actual operation -- changing repository is the correct mindset to solving the problem according to a coworker.
Select 'Team->Disconnect'
Select 'Team->Share' On 'Share Project' dialog
Select Git and click Next
Unselect 'Use or create repository in parent folder of project'
Select the new local repository
Checkbox the project name showing correct current location and target location
Click 'Finish'
Eclipse will move existing files from previous local repository to the new local repository.
I just renamed a repository. I use LiClipse, an Eclipse variant which includes EGit. I believe there is no way to do this operation with the EGit UI. Here's how I did it outside of EGit and Eclipse, without confusing them.
In the Git perspective, right-click on the repo, and select Remove repository from view... from the pop-up menu.
A dialogue box offers to delete the repository from the workspace. I interpreted this to mean, delete the repo directory and everything in it from my disk. Press the "No" button.
In the programming language-specific perspective (PyDev, in my case), right-click on the project, and select Delete... from the pop-up menu.
A confirmation dialogue box appears. In this case, I interpret it as just confirming that I want to remove the project's entry from the project list in that perspective. There is a checkbox, "Delete this project from workspace?". Leave that checkbox unchecked. Press the "Yes" button to confirm.
In the finder or command-line, find the repository directory, and change the directory name to the new name.
Return to Eclipse, and the Git perspective.
Select menu item, File... Open projects from file system.... (There is also a small icon with a "+", above the projects list, with tooltip "Add an existing local Git repository to this view". I believe it is different but equivalent.) A dialogue box appears.
Select the (renamed) repository directory. Click Next or Finish to complete the wizard. The Repository appears in the list of Git repositories in EGit.
Return to the programming language-specific perspective appropriate for that repository.
Select menu item, File... Open projects from file system.... A dialogue box appears.
Select the (renamed) repository directory. Click Next or Finish to complete the wizard. The Repository appears in the list of Git repositories in that language-specific perspective.
The project-specific Eclipse settings appear to be stashed away in a file .project within the repository, so they are not modified by the rename happening overhead.

How to properly use EGit with Eclipse

The only way I seem to be able to get use git in eclipse is to create a non-git project then turn that into a repository. This ends up moving the project out of the eclipse workspace on the file system. I then have to delete the project(it's still in the git repository), then import a git repository after creating a branch and clone it to get it back into the eclipse workspace.
Is there a simpler way?
I simply want to create project that is really a clone from a local repository. Essentially I have two copies on my HD but I can commit the eclipse project to the git repository. Unfortunately there has to be a better way?
To answer this question involves three steps.
Create a external (remote) repository
Share the project in a way that it remains in the workspace
Connect the project repository to the remote repository
Create a Remote Repository on Your Local Machine
Switch to the Git perspective. Click on Create a new Git Repository.
When a dialog appears select a directory where you would like your remote
repository to be. This is were your project will be pushed to. You will also
want to select the Create as a bare repository option.
That's it for this step. You should now have this repository in your EGit
repositories list.
Sharing Project within the Workspace
There are two ways to share a project so that it remains in your workspace.
1. Make the project directory a repository
2. Make the whole workspace directory a repository
The Project as a Repository
The first option option is not recommended by the Eclipse team. This issue is
described in more detail at Why is not recommended to have an Eclipse project folder as a Git repository?.
The basics of the issue are twofold:
You can't have more than one project per repository
If some thing happens to your workspace you'll lose your repository too
Issue 1 isn't solved here. Issue 2 can be solved by connecting to a remote
repository as show later.
To share the project as a repository:
Right click on the project
Select Team -> Share Project... from the popup menu
Click Use or create repository in parent folder of project
Select the project from the list
Click on the Create Repository button
Click the Finish button
Next you'll want to connect your newly created repository to the remote repository.
That's covered below.
The Workspace as Repository
The second options allows multiple projects to be added to your repository.
In fact any new project you create will automatically added to the repository.
Automatically adding projects can cause some issues.
One issue is that, if there are changes in multiple projects, staging
those changes can take a bit of wading through. Using a Tree presentation when
staging can simplify things.
Another more serious issue occurs when importing a git clone of a project into
the workspace. This importing will create nested repositories. Nested
repositories can cause problems
according to this post.
By default Eclipse doesn't import the git clone of the project into the workspace.
To share the workspace as a repository:
Right click on the project
Select Team -> Share Project... from the popup menu
Click on the Create button
Select your workspace as your Repository directory
Click the Finish button
Once your repository is created you may want to do a little house keeping. I suggest
adding the RemoteSystemsTempFiles project to the .gitignore file. Note: the
.metadata file is added automatically by Eclipse.
You can ignore the RemoteSystemsTempFiles by:
Switching to the EGit perspecitive
Selecting the workspace repository from the list of repositories
Select the Git Staging tab
Click on the View Menu button on the right side the the tabs toolbar
Select Presentation -> Tree menu (folders are easier to ignore form the tree view)
Right click on the RemoteSystemsTempFiles project
Select the Ignore Folder menu
Ignore other projects in the same way
Connecting to the Remote Repository
The last stage is connecting the workspace repository to the remote repository
we created earlier. Once you've switched to the EGit perspective:
Expand your workspace respository
Right click on the Remote node in the tree
Select the Create remote... menu
Leave the remote name as origin
Select Configure fetch
Press Ok
Click on the Change... button
Click on the Local File button
Select the bare repository that you created in the first section
Click Finish
Click Save and Fetch and then Ok
You can then stage, commit and push changes in your projects and workspace.
When you first commit and push EGit will push the default branch master
to the remote and configure pulling this branch from remote repository.
Follwing the User Guide, you would need to create the .git repo within your current project path:
If the .git path is within the current project path, there is no reason EGit moves your files anywhere else.

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.