Getting Started With Git and Eclipse EGit Integration Tutorial using GitHub

By Arvind Rai, July 31, 2015
This page will walk through the getting started with Git and Eclipse EGit integration tutorial using GitHub. Now days most of the software developer/student writes code on the Eclipse IDE and make their coding experience easy. We have a lots of valuable project and code that we programed and experiments on the system. But sometime we face the problem with our system (like system damaged, virus attack, HHD failure, etc.). In this situation we lost the project as well as code. But we have an alternate method to back up our project/code manually. Manual back up process is too lengthy and time consuming process.
Using Git Hub we may save our time and it's very easy process to store our projects/code online and access from anywhere. Now the problem is How to Install and Integrate Git Hub in Eclipse.
If you don't know the Git installation and integration don't worries, this page will help you with the concrete process.
If you are using the latest Eclipse (Mars) then need not to install the EGit otherwise you need to install EGit Plugin in your Eclipse IDE.

What is Git?

1- Git is version control system.
2- Git maintain the history.
3- Check In and Check Out control.
4- It provides an intermediate Git repository i.e. local git repository.
5- Git supports rapid branching and merging, and includes specific tools for visualizing and navigating a non-linear development history.
6- Repositories can be published via HTTP, FTP, rsync.
7- Efficient handling of large projects.

Mechanism of Git

While working with Git we will have 2 repositories

1- Git Remote Repository
2- Git Local Repository

Git is strong version control system that is secure as well. When we clone the Remote repository Git will create a local repository in the system. Creating a local repository in system will save damage of remote code. Suppose you are working with Project 1 and change the code of Project 1 and you want to review it but suddenly you have assigned for Project 2 then what you will do with those changes that you make in Project 1. Here we use the Git local repository. We commit the changes of Project 1 to Git local repository and start working with Project 2. Whenever Project 2 has completed then we rebase the Project 1 changes to our workspace.

Basic Requirements

1- Eclipse IDE
2- EGit Plugin
3- Gradle Build Tool
4- JDK 6
5- Git Hub account.

Eclipse Git Integration

To integrate the Git in Eclipse follow the below steps to better understating.
1- Go to Help >> Install New Software
2- Paste the below URL in Work with
3- Check all and proceed the Next
4- Wait until the installation has been finished. When the installation process has been finished restart the Eclipse.
5- To ensure that Git is successfully installed or not, go to Windows >> Show View >> Other >> Git. And you get five list in Git

Getting Started With Git and Eclipse EGit Integration Tutorial using GitHub

Working with Git in Eclipse using Github

Working with Git in Eclipse is very easy and reliable process. All the steps will described clearly below.

Create Github Account

To work with Github you need to create a Github account( When you have successfully create the account now create a Repository inside the account. After successfully creation of repository click on it and in the bottom of right side you will find the URL of the repository. Copy that URL for cloning in Eclipse. Note : Do not forget to create a file inside the repository.

Clone Git Repository

1- Open the Eclipse >> Windows >> Show View
2- If you find the Git in list click on it otherwise click on Other
3- Find the Git >> Git Repositories
4- Click on the Clone a Git repository

Getting Started With Git and Eclipse EGit Integration Tutorial using GitHub

5- Fill required detail and proceed Next

Getting Started With Git and Eclipse EGit Integration Tutorial using GitHub

6- Followed Next check the master and again click the Next.
7- Set the location of your local workspace and check the Projects >> Import all existing Eclipse project after clone finishes >> Finish
8- When the process has been finished it will import all project if exist in the repository other you need to create the project.
9- To create and import the project go to the Git Repository >> Working Directory >> Right click on it >> Import Project >> Next >> Finish
10- Now your Repository/Project will show in eclipse navigator/project explorer.
11- Create a folder src/main/java
12- Start making the java class and check-in the code on Git Hub.

Use Gradle to Set Classpath and .project in Eclipse

Gradle build tool is the most popular build tool that is used in software industry. To download Gradle build tool got to the below link Steps for Gradle-

1- Set the path of Gradle in Environment Variable.
2- Now create the file in your root directory named build.gradle in Eclipse.
3- Paste the below code in build.gradle file and save it.
apply plugin: 'java'
apply plugin: 'eclipse'
archivesBaseName = ''
version = '1.0'
repositories {
4- Now open Command Prompt >> go to your project >> type gradle eclipse >> Enter

Getting Started With Git and Eclipse EGit Integration Tutorial using GitHub

5- Gradle will set all the setting that is required.
6- Now your project is a Java project and you are able to create the package as well as class.

Check-In and Check-Out Code from and To Remote Git Repository(Github)

This figure is clearly show that the work flow process of Git.

Getting Started With Git and Eclipse EGit Integration Tutorial using GitHub


Check In is a process to send the code in Git repository. How to check in your code look at below steps
1- To check in the code you will need Git Staging Tab in your Eclipse.
2- To get Git Staging Tab. Go to Window >> Show View >> Other >> Git >> Git Staging
3- Refresh your project. All the file will come in Unstaged Changes >> select all and drop in Staged Changes, >> write the Commit Message >> Commit and Push

Getting Started With Git and Eclipse EGit Integration Tutorial using GitHub


Check-out is a process that brings the code from Remote Git to local workspace and it has two processes.
Fetch from Upstream: As in above figure we can see that Git has a local workspace. When we fetch the date it will come to the Git local workspace/repository.
Rebase: Rebase is a process that fetch the data from Git local repository to Eclipse workspace.

Show History and Compare Code using Git in Eclipse

Show in History : This feature will show all the commit history that you had committed. While clicking on the commit you will see the changes.
Compare with HEAD Revision: This will compare from the current code from workspace and existing code from remote section.
Compare with PREVIOUS Revision: It is just opposite of Compare with Head Revision, it will compare the previous code of remote and local workspace.

Expected Error

If the project extension is not a Java Project then it will show you such type of message Source folder is not a Java project. To make the source folder as a Java project and set all setting of Eclipse properly you need to run Gradle Build Tool.

©2024 | Privacy Policy | Contact Us