Confusing Eclipse and Github interactions - eclipse

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

Related

Git hub project _ Learning)

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.

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.

How to get src folder under project-root folder in github when staging from eclipse using egit

Current scenario :
In Eclipse when we create a project, say a PyDev project named ‘SimpleGit’, the folder structure created by eclipse will be like
EclipseWorkingDirectory/SimpleGit/src/
correct?
If we add this to git using Egit, by right clicking on the project folder SimpleGit then Team>Share, The folder structure in which repo is formed like this
Parent Folder/ SimpleGit/ .git
Parent Folder/ SimpleGit/SimpleGit/src/
And when we stage it to remote github everything will come under
Username/ SimpleGit / SimpleGit / src /
So when we look in GitHub in the root project folder (Username/ SimpleGit) we can’t see the source folder. It will be under another folder ‘SimpleGit’. How we can avoid this?
What I want is , I want to get my source forlder(src) listed under the Project Root directory, when staging from an already built project in eclipse using egit. How do I do this?
I want like this:
https://github.com/nicholasbishop/blender
Not like this:
https://github.com/afilash/SimpleGit
it cannot be done using eGit - it assumes the Eclipse project structure.
But it can be accomplished by using git itself. Just create a repository under SimpleGit folder executing 'git init'. From that point on you'd have to manage your git repository by either git itself (command line) or some other UI. SourceTree works really well for me.
It is a bit late, I know, but this method perfectly works and I hope it is useful for anyone who sees this post from now on.
The procedure is the following:
First step is creating a repository on Github (through github.com)
Move to Eclipse IDE (Git Repositories view) and click "Clone a Git Repository and add the clone to this view". Doing that the project will be somewhere located on the hard disk. Usually, it is stored in C:\Users\username\git\projectName but you are able to change it. This is our local repository.
Once done, press (in Eclipse IDE) File->Import->Projects from Git->Existing local repository(Select the one you cloned before)->Import using the new project wizard->Finish->Java->Java Project->Specify project name (just below the dialog box there is a checked checkbox that says use default location, uncheck it. Here is where you have to specify the directory you chose while cloning the repository previously).->Next->Finish
It should be enough for creating the right directory structure.

Does git exclude eclipse project files from a new repo by default?

I have tried pushing several eclipse projects to github repos. Every time I have trouble later cloning or fetching them back into eclipse. The reason seems to be that the eclipse specific project files (.project, .classpath, etc) are not staged when I do a 'git add .' I have tried researching gitignore files but cannot find one created by default. The file in .git/info/exclude also seems unrelated. I've searched StackOverflow and the internet at large and find no mention of this. So obviously I'm the only person this has every happened to or the only dummy who can't figure it out on my own. Do I need to stage those project files explicitly to include them in them in the repo (after adding a whole project with a 'git add .')?
If those Eclispe project weren't in a git repo locally, you can create a git repo at the root directory of your project, and you should be able to add the files with a '?' on them, including the .project and .classpath:
(From Egit User Guide / Create Repository section)
But if the project is already in a git repo, check first in the git command-line those files status. In doubt, always fall back to the CLI (command line interface), with any local git installation (for instance for Windows: msysgit)
The EGit Eclipse option "Import > Git > Projects from Git" should reference all the files, included the .project and .classpath
I'd recommend using Egit instead of the command line in this case. While the command line is typically more powerful, Egit knows better about the logical project structure of an Eclipse project.

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.