How to add Git-Lab on Eclipse?
So that I can just push or fetch from GitLab. I am a newbie in this, please give more explanation.
How do I add a repository to Eclipse?
Create a local Git repo for your Eclipse project With your project open in Eclipse, right-click the project name in Project Explorer and select Team, Share Project... Select Git and select Next. Select Create... from the Configure Git Repository window and choose a folder for your local Git repo. Select Finish.
I Preparation
Make sure you have eGit in Eclipse:
- Help -> Installation details
- See that "Eclipse Git Team provider" is in the list.
If it is not installed, follow the indications in the answer from @VonC
Make sure you have the URL to the repository in GitLab. Something like https://gitlab.com/<someusername>/<somerepository>
You get it from gitlab.com when you are at the overview page for the project:
- Menu (the hamburger icon ≡, 3 horizontal lines),-> projects, then click in the one you want to work with from eclipse. Now you are in the overview page. Right beneath the name of the project and its description there are a few buttons to allow you to perform some actions. One of those buttons is a selector for SSH/HTTPS protocols. For now, select HTTPS and copy the URL that follows it: that is the URL to the project.
II Now clone the repository locally, using Eclipse eGit.
These steps have been tested in Eclipse Kepler and Eclipse Luna. Rumor has it that they are outdated and might not work as indicated. If you use a newer Eclipse, take care and post back the new steps :-)
- Window -> Open Perspective -> Other
- Search for "Git", select it, and click "OK"
- Click the button with an arrow and the tool tip "Clone a Git repository and add the clone to this view"
- In the "Source Git Repository" wizard:
- URI: the URL from the repository in GitLab, like
https://gitlab.com/<someusername>/<somerepository>
- eGit has filled in the host and repository path for you.
- Leave the connection as it is (https and no port) and fill in the details for the authentication: user and password you use to log in GitLab.com.
- If you tick the "Store in Secure Store," Eclipse will handle user/password for you from now on; I do it, but it is not advisable if you share Eclipse installation with someone else, or you do not trust your PC to hold your passwords.
- Click next
- Branch selection wizard.
- If there are more than one branch in the repository, you may now choose which one you want to clone locally, the one with which you want to interact. You may also choose to clone all branches to have them available.
- Once you are done, click Next
- Local destination wizard.
- You may now choose where you want to place your local Git repository. eGit defaults to a subdirectory under you user, unrelated to eclipse, it works well. If you do not like it, change to your liking.
- As with other Git installations, it will name the GitLab.com repository as "origin". You may also change that if you really want.
- In the projects box check the "Import all projects" and, if you work with "Working Sets", you may choose now in which one to place it.
- Click Finish.
eGit now works for a bit and shows you the newly cloned repository in the view. You have a cloned repository with which you will be able to interact from Eclipse.
III Now import the project into Eclipse.
- File -> Import...
- Git -> Projects from Git -> Next
- Existing local repository -> Next
- Select the newly cloned repository -> Next
- Import using the New Project Wizard -> Finish
- Choose the project type that is hosted in GitLab.com. In my case is "Java Project;" in other occasions it has been "Maven -> Maven Project". Then click Next
- Name the project and change the settings you want. As destination, do not use the default location, but navigate to the location of the cloned repository (as used in step 6 in the previous section cloning the repository) -> Next
- Verify that the import looks like you want it and click Finish.
You may now work within Eclipse and use the Team menus to sync and commit and push.
The easiest way is to usean Eclipse with EGit (http://www.vogella.com/tutorials/EclipseGit/article.html)
See "Compare Eclipse packages" (the standard Eclipse, for instance, has EGit)
This will allow you to add a remote repo url referring to your gitlab repo hosting server.
This isn't specific to gitlab though, and you could add remote repos referring to Github or Bitbucket.
http://wiki.eclipse.org/EGit/User_Guide#Working_with_remote_Repositories