Using EGit: Introduction

You may need to share some projects with your development team. Moreover, you might want discard your modifications in a project and revert back to an older version. We recommend you to use Git, a distributed version control system that emphasizes speed and efficiency. In this page, we describe how to use EGit, a Git implementation used within the Eclipse IDE, for some typical use cases.

Note that you can also install git command-line software and other GUI tools. However, we will use EGit here.

This is not a tutorial on Git. However, a short description about Git is given. The full features of EGit are not covered either.

Installing EGit

If you have not installed EGit, do the following steps:

  • In Eclipse, select Help - Install New Software.
  • Type “git” in the first text field in the opened window.
  • Select the only option shown on the drop-down list. It should contain the update side of EGit: http://download.eclipse.org/egit/updates
  • Select Eclipse EGit.

  • Follow the next step by clicking button Next until the plugin is installed.
  • After the installation, restart the Eclipse IDE.

Now let us open the Git Repositories view which is used to manage repositories:

  • Select Window - Show View - Other.
  • Type “git” on the search field at the top.
  • Select Git Repositories.

You should see a window like the following figure.

Setting Identity

An important thing to do before working with Git is to set your name and email which are used to identify who do changes.

  • In Eclipse, open the Preferences window. For Mac OS, select Eclipse - Preferences. For Windows, select Window - Preferences.
  • Find the Git configuration preferences by selecting (1) Team - Git Configuration on the left hand-side list. You can also just type “git” in the filter textfield on the top left and then select “Configuration”.

  • Click the (2) New Entry button. You will get a new window like the following figure.

  • Fill in the Key field with user.name and the Value with your name.
  • Click OK.
  • Click again the New Entry button.
  • Now fill the Key field with user.email and the Value with your email.
  • Click OK.

Git in a Nutshell

If you already familiar with Git, you can skip this section. This part is not intended to describe Git in detail. Read the Git Pro book by Scott Chacon, if you want to learn more. Git is a Distributed Version Control System (DVCS) which handles data differently than most other VCSs. Usually, VCSs store information as a set of files and the changes made to each file over time. In Git, every repository has a complete history and full revision tracking capabilities. Fig 1-4 (How other VCSs store data) and Fig 1-5 (How Git store data) in the Git Pro book illustrate this difference. Git is also a fully distributed VCS. It does not depend on a central server nor network access.

Repository

A repository can contain several projects. In EGit, these should be Eclipse projects and for us projects or libraries containing building blocks. We recommend one Git repository contains one project in order to be able to maintain your projects easily. In this documentation, we assume this is the case. In order to share a project with your development team, you need to store the content of your local repository in your machine in a remote location (a Git server or a hosting service). Obtaining a shared project is achieved by getting a copy of an upstream or a remote repository into your machine.

Working Directory

A Git repository also contains the history of its content, i.e., a project. The Git working directory is a single checkout of one version of the project. If the project is also in your Eclipse workspace, the version in the workspace is the same as the one in the working directory. Relations among local repository, remote repository, working directory and the Eclipse workspace can be depicted in the following figure. They will be explained further with four typical use cases.

Git Project Hosting Service

You can use a hosting provider for Git projects to store a copy of your repository remotely and share it with your development team. There are several providers, e.g., Github and Bitbucket. Here, we use Bitbucket. To use Bitbucket hosting service, you need to create an account.

  • Go to the signup page.
  • Fill in the necessary information. You can use Individual account.

We can use HTTPS or SSH for the communication protocol between local repository and Bitbucket. To use HTTPS you need to supply your username and password. To use SSH, you need to set up an RSA key pair if you do not have them. Here, we will use HTTPS.

Typical Use Cases

We show four cases, namely: