I have a working Spring Boot application that I created in Eclipse that I wold like to put into a new Git repository.
Unfortunately, I cannot seem to do this using Eclipse (or any other Git tool).
I am using Eclipse v2019-06 (4.12.0) and the Spring Tool Suite (STS) v4.3.1
To illustrate the problem, I take the following steps:
I create the Spring Boot project using STS:
Click on "Create a Project"->"Spring Boot"->"Spring Starter Project"
Project name is GitProject
Nothing fancy in this project. Createed a HelloController class that returned some HTML. Ran a browser to test it and displayed a "greeting" web page.
Compile project
mvnw clean package
Successful compile. Ran and successfully displayed web page:
java -jar GitProject-0.0.1-SNAPSHOT.jar
The project is successful and the service works. Place project into Git
There are procedures described to create and push to new repositories. Based on procedures provided in Stack Overflow answers, perform the following:
Create the repository
git init
Make it bare
git init --bare
Create a basic README file for adding to the repository
echo Testing > README
Add and commit the README file
git add README
git commit -m "Initial Code"
Now put the project into the repository. Or at least, attempt to...
Create a project in a different folder, importing from the new repository
Click on "Import projects..."->"Projects from Git"
Clone the URI from the new repository, Only the master branch is available. Place the destination in the project folder. Because there is no existing project in the new repo, and since the IDE does not offer a way to successfully create a new Spring Boot project from a repo (I made several attempts to use the New Project Wizard to create an STS project when creating the repo. Every attempt led to different Exceptions being thrown while creating the project), select "Import as General Project" in the "Select a Wizard" dialog.
Go to the folder with the original GitProject project. Copy everything from that folder and paste it onto the new project
Edit the .gitignore file that gets included in the Spring Boot project. It is important to remove all references to the STS files except for the .sts4-cache file. These need to be saved at least once in order to ensure that the Spring Boot information is saved in the repository.
Right- click on the project and select Team->Commit
Stage everything, enter a commit message, then click on "Commit and Push"
See the following failure:
master-master [remote rejected]
Repository
branch is currently checked out
error: refusing to update checked out branch: refs/heads/master
error: By default, updating the current branch in a non-bare repository
is denied, because it will make the index and work tree inconsistent
with what you pushed, and will require 'git reset --hard' to match
the work tree to HEAD.
You can set the 'receive.denyCurrentBranch' configuration variable
to 'ignore' or 'warn' in the remote repository to allow pushing into
its current branch; however, this is not recommended unless you
arranged to update its work tree to match what you pushed in some
other way.
To squelch this message and still keep the default behaviour, set
'receive.denyCurrentBranch' configuration variable to 'refuse'.
What is strange is that somehow this branch remains "checked out" after being cloned but the IDE does not appear to provide a way to "check it back in". Worse: I actually tried just cloning the new repo, changing the README file, then committing and pushing it (without including the Spring Boot code) and that attempt yielded the same failure.
So how do I get this code committed and pushed into my repository? What step is missing from the documentation of how to do this???
Related
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.
After several attempts of merging the project is unusable and broken. I want to return wholly to an old remote branch. But after checkout branchin Git Extensions when I try the Maven Update I am getting message:
Unable to update Maven configuration
Could not set the project description for 'cm' because the project description file (.project) is out of sync with the file system.
Clean Project, Refresh won't help. (no changes)
Try doing a checkout with hard reset to the remote branch, this will restore the working directory to the remote branch's state removing any new files.
If your remote branch was in working condition then you should be able to run "maven update".
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.
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
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.