Git hub project _ Learning) - eclipse

I am working on a simple project to learn github. After I worked on my project in eclipse on my local computer, I pushed my project to github for other teammates. A second member of my team pulled this project from github and pushed back to github after making some changes. Now this morning I want to pull this updated project from github to my local machine (eclipse) so I can work on this updated project.
How can I pull this updated project from github to direct into eclipse on my local computer .
I am tried to do:
"git clone http://github.com/testproject/gitDemo.git" but it is not directly going to eclipse. If I save this project on my machine and then try to import into eclipse I got error message, "can not import, there is already one project exist with same name".
I did not see pull option in eclipse under:
Right click on project - team - Pull
Any suggestions??
Thank you in advance for all your help

I'll make one point that I'm not certain you do NOT understand, but as I often see this misunderstood, I'll point it out.
You should separate the notion of "git repository" and "project". When you clone a git repository from github (or bitbucket, or some central repository), you should store it in a directory tree outside of your Eclipse workspace. You then should right-click on the repository and select "Import..." to create a project from the contents of that repository.
Related to that, you should look for the "Pull" operation on the repository entry, not the project. I recommend to display the Git Repositories view on the left side, below the Package/Project Explorer, and make sure that you attempt all git operations in that view, instead of the Package Explorer view.
The only detail from your original post that I can address is the error about already having a project with that name. That error message is not ambiguous at all. You already had a project with that name. I have no idea whether that project was a copy of the repository that you had somehow already imported, or whether it's an empty project, or what. You don't provide any information about that.

Related

How can I start a project on GitLab repo with Eclipse?

Good morning.
I just create a GitLab private repo to work in a project with some people. When I add GitLab repo to Eclipse, it says there aren't projects (and it's true). I would know how to create a project and sync with online repo so other members can see my project and codes.
I tried to start a project in git\repoName\ folder, then right-click and choose Team->Commit, but changes wouldn't save (in gitLab repo's website, it says "Repo is empty").
I tried to follow some online guides, but without success.
Sorry for bad english!
Eclipse 4.2 and newer, comes default with (E)Git installed. There is a good Eclipse git tutorial from Vogella.
Create a GitLab git repository
Log into GitLab
Create a project / git repository
Copy the https url from the project, used for cloning
Adding an GitLab git repository in Eclipse
Open the Git perspective in Eclipse
Use Clone existing Git repo, as shown in Using git repository view
Now all the git functionality from Eclipse can be used.
I assume you have a cloned repository available in Eclipse (eGit) that is empty. If not, follow the steps in the answer from Verhagen.
By now, you have a cloned repository that is marked with "[NO HEAD]", indicating that no commit has been made.
Start creating a new project by using your project type of choice; I'll use Java project for simplicity: File menu > New > Java project
in the New Java Project wizard un-tick the "Use default Workspace location" checkbox; instead, choose the directory where you cloned your empty GitLab project, and append the name of the project (this is to make Eclipse create a directory inside the repository, just in case you later want to create more projects in the same repo).
Fill in the wizard as you usually do. When you are done with the different steps, you'll have a new project, that is also marked with "[NO HEAD]"
Create some source files you want to share (e.g. HelloWorld.java)
Synchronize workspace (right click on the new project > Team > Synchronize workspace) you will see that now there are files to commit. Pay attention to those files, since some of them ( .gitignore, and maybe .classpath, .project,.settings directory... depending on how you share your projects) you'll want to add to the .gitignore.
right click on the files you want to commit, fill in the commit message and click "Commit and Push". Click Next
Since it is a new repository, you'll have to configure the Push action. I selected HEAD as source and HEAD as destination. You might want to do the same, at least for this first commit+push; later on, you might choose to add some specs for branches, etc.
The Push Confirmation will show you that the new branch master:master will be created.
Both project and repository lost the "[NO HEAD]" marking
You can check gitlab site to confirm your files are there.

Confusing Eclipse and Github interactions

We are trying to use Eclipse and github on a project, and it is proving to be a real burden because we do not understand how it works. It is difficult to formulate a single question, but let's start with one case:
We have a project in Eclipse that is on github. Several developers are sharing the archive. We learn that we want to create a Java EE project rather than a Java project. We do not want to change the name of the project. How can this be done?
Further, not knowing this, we tried to change the name from ProjNamet to ProjName2.
When creating a project on git, Eclipse creates it in a local directory:
c:/Users/username/git
In order to push that project out to github, we executed:
git remote add origin github.com/author/projname
git push origin master
As far as we can see, the project appears to be successfully pushed out to github.
In addition to source code, there is:
.project
.gitignore (which just ignores the build directory)
.classpath
.settings
But when I right click on the repository and try to import projects from it to my computer, Eclipse failed
deleting the directory, and clicking on File->import.. and importing from the repository works.
I do not see what the difference is between the one that worked and the one that did not.
Try this:
git remote add origin github.com/author/projname
git push origin master

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.

How do I reconnect a moved git repository with it's original project in Egit?

I have a number of projects within an Eclipse workspace. One project is connected with a git repository. This is the original directory/project structure:
Eclipse_workspace
Eclipse_workspace/Project1
Eclipse_workspace/Project1/.git
Eclipse_workspace/Project2
After reading about the complications that can arise from keeping a git repository within the parent directory of a project in a workspace (here), I decided it would be best to move the repository outside the workspace. Here is the revised structure:
Eclipse_workspace
Eclipse_workspace/Project1
Eclipse_workspace/Project1
Eclipse_workspace/Project2
.git
.git/Project1
Within the "Git Repositories" view I re-added the repository. I thought it would be simple to reconnect the repository to "Project1" by altering a few file path settings. I found that this was not possible from Project1's properties (right click on project -> properties). I noticed that within the "Share Project" wizard you can connect to an "existing repository". So I disconnected the project from the now non-existent repository and I tried to reconnect it using the "Share Project" wizard. But although the repository is shown in the "Git Repositories" view, I was unable to select it. I clicked the "create" button and tried typing in the file path but this gave me an error stating that the directory is "not empty".
So I have now become stuck as there seems to be no other options available. How can I reconnect this repository? I'm surprised by how complicated this is, I must be doing something really obviously wrong. I really need to get on with some work and messing around with Egit is taking up all of my time.
I ran into this same problem and here was my solution:
Copy your repository(including the .git directory and the working directory) to wherever your new location.
Add your new repository in the "Git Repositories" view in eclipse.
Then import your "Projects from Git".
The point is: try not to reconnect, just import the projects from your new repository into your eclipse workspace.
Hope this helps.
Select your project(If you have many projects don't forget the clic to the right one)
*clic right -->team -->Share project
Go to your project directory
open a console - type cmd
run git init
check your branch with - git branch
change branch - git checkout
note:
You need to have a git tool installed in your computer.
it worked for me.

How to create Eclipse project with EGit clone

After spending a decade with SVN I've finally taken the plunge with Git. I have set up Git, Gitolite and GitLab on a server and have successfully added code to my local repository, committed, cloned repositories and pushed code back to repositories. So far, so good. Now enters EGit...
I have cloned a repository using the Git Repository Exploring view using the following syntax for the path:
ssh://dexter:vaultanalyser.git
(In GitLab, repositories are referred to as projects, so I assume that I am supposed to have one repository per Eclipse project? Rather than a SVN-style single parent repository that contains multiple projects?)
This imports the repository into:
/Users/mattpainter/git/vaultanalyser
I was expecting this step to automatically create an Eclipse project for me with all the source, but this isn't so. I tried fudging the target directory so it's in my workspace, but this isn't working either.
How do I get the cloned source available within Eclipse? This site implies that if you create a project with the same name as the repository, it all magically works, but this isn't the case (yes, I know the article is about Github, not GitLab, but I figured the two were close enough for the task at hand).
I've then tried creating a project in Eclipse and sharing it - but then the whole project appears as a sub-folder in the repository. If repositories are indeed analogous to projects, this isn't really what I want.
I've looked through other StackOverflow topics that look related, but I fear I'm still missing a key piece of understanding with how this is supposed to work and it's all looking remarkably convoluted thus far.
Help?
In GitLab, repositories are referred to as projects, so I assume that I am supposed to have one repository per Eclipse project?
Yes, but a GitLab "project" isn't necessarily an Eclipse one.
It doesn't have to follow an SVN structure, as illustrated in "Eclipse reference directory outside eclipse project directory but within repository".
All you need to do is to create an Eclipse project, specifying the source directory being not in the default path (Eclipse workspace), but wherever you cloned your repo (as described in "Getting started with Eclipse + EGit - confused").
That way, the eclipse project you just declared (and referenced in the Eclipse workspace) has its files (.project and .classpath) at the root of the Git repo.
And Egit can then manage that project just fine.
Or you can import it directly with Egit: "Eclipse + EGit: clone project into workspace".
As the OP nullpainter reports below:
The original issue was compounded by invalid permissions in the .git/objects folder on the server.
Running a chmod git:git -R * on the folder solved the issue
He details the right setup below.
To expand on #VonC's answer, the steps to get EGit and Eclipse to play nicely is:
Select 'Clone a Git repository' from EGit, accepting all defaults. This will create a folder in a git parent folder, somewhere outside your workspace.
Create a new Eclipse project. I'm using Java, but I assume there are similar steps for other languages. On the first dialog, untick 'Use default location' and instead select the repository folder created in step 1. Accept all defaults.
Select Team > Share Project... from your new project. Select Git, and tick the 'Use or create repository in parent folder of project'.
Now you can push your code and Eclipse dot files to your git repository from within Eclipse.
(My original issue was compounded by invalid permissions in the .git/objects folder on the server - running a chmod git:git -R * on the folder solved the issues)
I check it out with the command line - then build my projects on top of that. In fact, I end up doing most operations with command line git. EGit is useful for viewing the diffs but I find command line has more power and control. Git is mostly about giving devs lots of power and control.