Using Git with Eclipse

These directions extend the Using Git from the Terminal or Git-Bash directions, and they provide the very basics to clone your repository into an Eclipse project. Replace your credentials with these when completing this tutorial: user name is newuser, with some password, and the remote repository is http://projects.cs.uaf.edu/newuser.

After completing these steps, play around with the Git Repository perspective to familiarize yourself with it. In addition, make some changes to your files and commit them after each change, then view your remote repository.

Installing Git in Eclipse

This section assumes you have the Eclipse IDE installed on your system. If you are using your own computer, follow these instructions if you have not installed EGit into Eclipse yet.

Eclipse uses EGit to access remote repositories.

EclipseMarketplace.png

Open Eclipse Marketplace from the "Help" menu.


Select Help > Eclipse Marketplace and search for EGit, then install EGit.

EclipseMarketplaceEgitSearch.png

Search for EGit, then install EGit and JGit.


Setting up EGit Preferences

After installing EGit, open the Preferences pane and navigate to Team > Git. Set your default repository folder.

EclipseDefaultFolder.png

Setting your default repository folder.


Cloning from your remote repository

Cloning from your remote repository allows you to push and pull changes to and from it.

EclipseImport.png

Choose File > Import.


EclipseImportProjects.png

Choose Git > Projects From Git.


EclipseImportUri.png

Select "URI" for your repository source.


EclipseImportSource.png

Enter your remote repository information.


EcplipseImportMaster.png

Choose the "master" branch.


EclipseImportSetDirectory.png

Make sure the directory is set correctly.


EclipseImportGeneral.png

Choose "Import" as a General Project.


EclipseImportClone.png

Ensure the Project Name is set correctly and click "Finish".


Opening your Git Repository Perspective

EclipseImportOpenPerspective.png

Select Window > Open Perspective > Other.


EclipseImportGitRepository.png

Choose "Git Repository".


You should now have cloned your remote repository.

EclipseImportAfterClone.png

Your Git Repository after cloning.


Creating a New File

Select Window > Open Perspective > <your perspective>. I opened the Java EE perspective to write a Java program, for example.

EclipseCreateNewFile.png

Choose the folder to create the new file in > New > File.


EclipseCreateHomework2.png

Create a file named Homework2.java and fill in with text.


Pushing to the Remote Repository

Now that you have made a change by adding a new file, we can commit the change and push it to the remote repository.

EclipseGitTabs.png

Right-clicking folder > Show In > History is an easy way to get to the Git functions.


EclipseGitCreateStaging.png

Drag the file(s) to Staged Changes, add a message, then "Commit and Push".


EclipseCreateConfirmationMessage.png

A confirmation message pops up.


EclipseCreateRepoView.png

If you followed the steps correctly, you will see this in New User's repository view.


EclipseCreateConfirmationMessage.png (50.5 KB) John Quan, 06/24/2013 01:43 PM

EclipseCreateHomework2.png (45.2 KB) John Quan, 06/24/2013 01:43 PM

EclipseCreateNewFile.png (104 KB) John Quan, 06/24/2013 01:43 PM

EclipseCreateRepoView.png (232 KB) John Quan, 06/24/2013 01:43 PM

EclipseDefaultFolder.png (117 KB) John Quan, 06/24/2013 01:43 PM

EclipseGitCreateStaging.png (89.8 KB) John Quan, 06/24/2013 01:43 PM

EclipseGitTabs.png (246 KB) John Quan, 06/24/2013 01:43 PM

EclipseImport.png (66.1 KB) John Quan, 06/24/2013 01:43 PM

EclipseImportAfterClone.png (159 KB) John Quan, 06/24/2013 01:43 PM

EclipseImportClone.png (50.8 KB) John Quan, 06/24/2013 01:43 PM

EclipseImportGitRepository.png (41.8 KB) John Quan, 06/24/2013 01:45 PM

EclipseImportOpenPerspective.png (48.6 KB) John Quan, 06/24/2013 01:45 PM

EclipseImportGeneral.png (77.5 KB) John Quan, 06/24/2013 01:45 PM

EclipseImportProjects.png (59.5 KB) John Quan, 06/24/2013 01:45 PM

EclipseImportSetDirectory.png (68.4 KB) John Quan, 06/24/2013 01:45 PM

EclipseImportSource.png (68.1 KB) John Quan, 06/24/2013 01:45 PM

EclipseImportUri.png (52.5 KB) John Quan, 06/24/2013 01:45 PM

EclipseMarketplace.png (61.7 KB) John Quan, 06/24/2013 01:45 PM

EclipseMarketplaceEgitSearch.png (110 KB) John Quan, 06/24/2013 01:45 PM

EcplipseImportMaster.png (61.9 KB) John Quan, 06/24/2013 01:45 PM