How can I add current Eclipse project to git with EGit? - eclipse

I have GAE project in my Eclipse and I want to add it to my local git repo, how can I do that?

Since creating a Git repo within a GAE project is possible through command line, it is possible through Egit:
Follow that Egit tutorial:
For a new repo:
Right click your project, select Team -> Share -> Git.
Select the proposed line and press "Create repository". Press finish
Create the file ".gitignore" in your project with the following content.
All files / directories which apply to the pattern described in this file will be ignored
But you can also add it to an existing local repo by:
making a special branch for your project in your local repo (with just the .gitignore file in it)
clone it where your current project is
add all your current project files in it
import said Git repo into your workspace: See 4.2 Clone existing project.
informatik01 adds in the comment a link to a short article describing how to do it using the command line:
Adding Eclipse Project to Git
cd ~/workspace/my-project
git init .

Related

Creating Spring Initializr Project for existing Git repository in Eclipse

I'm confused how to setup my project correct. There is already a existing git repository named "DatabaseHub" which is only containing the README.md after my first commit. Then I have there my Spring Initializr zip which I want to use for this repository. I named it databaseHub as well. It's a Gradle project.
When I'm trying to create the project with this zip in Eclipse in my git project I fail.
What I tried: Cloned the git repo (so it is in the project explorer), tried to import the extracted initializr zip with the option "Existing Gradle project" but this won't work cause of the name collision.
I don't get what's the right attempt to start this. Just putting all the files manually in the repo doesn't let Eclipse know that it's even a project now.
Eclipse version is 2019-09.
Try and unzip that project elsewhere on your disk.
Then go to your local Git repository (the one with the single README) and do:
cd /path/to/local/Git/repo
git --work-tree=/path/to/unzipped/project add .
git restore -- .
git commit -m "Import project"
The git restore -- . step (with Git 2.23+, August 2019) will make sure your imported files are checked out and visible within your local repository.
Finally, import the Gradle project: Eclipse should detect the Git repository in it (if not, do a Team > Share)

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.

Git working copy into Eclipse

I can't figure out why I can't get a working copy from a git repository into Eclipse PHP Explorer.
I think to have followed the steps I have been reading:
http://wiki.eclipse.org/EGit/User_Guide#Cloning_Remote_Repositories
http://www.vogella.com/tutorials/EclipseGit/article.html
But at the end of the procedure I don't have the code at the PHP Explorer. But the way, at Git perspective I can see the git repository.
The only options I can see at Team context-menu, are:
Apply Patch
Share code
By "share Code" option, the project files are moved into the git repository folder. By doing this:
the project tree parent has detected the git repository, I can see at the root tree [gitpoject git]
at the project properties, on Git section, I can see the Git repository data correctly
The Team contextual-menu has now the expected Git commands
If I do a commit from the root-tree, the Commit windows is shown and wants to add the Eclipse project structure.
But I can't see the code holded into the git repository into the project.
I tried to clone the git repository with "Git Bash" by one side, and import this folder into an existing project without luck.
Anyone could help? Thanks in advance.
Even if this not responds completely the problem I have explained, the only way I can have a working copy into the Eclipse PHP Explorer is by:
Make a git clone through Git Bash
Create a new project (PHP Project) and select "Create project at exisiting location" for Contents
By selecting the directory I have the repository cloned, I can see the contents of this repo now at the PHP Explorer and use the Git tools.
If someone could clarify why the procedure I have followed has not worked I will appreciate to understand it.

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

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.