How to add GitLab repository in Eclipse?

2019-03-08 08:51发布

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.

4条回答
别忘想泡老子
2楼-- · 2019-03-08 09:00

I Preparation

Make sure you have eGit in Eclipse:

  1. Help -> Installation details
  2. 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 :-)

  1. Window -> Open Perspective -> Other
  2. Search for "Git", select it, and click "OK"
  3. Click the button with the blue arrow and the tool tip "Clone a Git repository and add the clone to this view"
  4. 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
  5. 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
  6. 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.

  1. File -> Import...
  2. Git -> Projects from Git -> Next
  3. Existing local repository -> Next
  4. Select the newly cloned repository -> Next
  5. Import using the New Project Wizard -> Finish
  6. 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
  7. 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
  8. 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.

查看更多
Emotional °昔
3楼-- · 2019-03-08 09:04

Install Egit in eclipse using Install new software from http://download.eclipse.org/egit/updates.

查看更多
手持菜刀,她持情操
4楼-- · 2019-03-08 09:12

It seems that there is a Mylyn Gitlab Connector now.

I think I'll give it a try

查看更多
太酷不给撩
5楼-- · 2019-03-08 09:20

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

http://wiki.eclipse.org/images/3/35/Egit-0.9-clone-wizard-url-page.png

查看更多
登录 后发表回答