Professional Documents
Culture Documents
Git Version Control With Eclipse Tutorial
Git Version Control With Eclipse Tutorial
NOTE: This description contains information about working with Git in Eclipse, but it does not
cover all concepts for Git. To learn about git, please see Getting Started with GITLAB
What is EGit?
EGit is an Eclipse plug-in (software component) which allows you to use the distributed
version control system Git directly within the Eclipse IDE. EGit is based on the JGit library.
JGit is a library which implements the Git functionality in Java.
Most Eclipse 4.2 and Eclipse 4.3 downloads from eclipse.org contain EGit in their default
configuration. In this case no additional installation is required.
If the EGit plug-in is missing in your Eclipse installation, you can install it via the Eclipse
installation manager. Start this manager via the Help → Install new Software... menu entry.
http://download.eclipse.org/egit/updates
If you do not see “Eclipse Git Team Provider” in the list of software, you probably have it
installed already. Continue to next step.
The Git configuration settings can be adjusted via the Eclipse preference setting.
You can add entries to your Git configuration by pressing the Add Entry... button on the Git
Configuration preference page. To add your user, use the user.name as key and your real
name as value. Repeat the procedure for your email address.
Note:You can also use Eclipse configuration variables to define this path, e.g. if you want to
store repositories in the folder "git" under the Eclipse workspace you may use
${workspace_loc}/git.
To simplify access to the common Git operations you can activate the Git menubar. For this
select Window → Customize perspective... and check the Command groups Git and Git
Navigation Actions in the Command Groups Availability tab.
Depending on your installation you may have to select that you want to use Git as a version
control system.
It is recommended to separate your Git repository from any additional meta-data which
Eclipse might create, it is recommended to place your Git repositories outside the Eclipse
workspace. Eclipse follows this recommendation and the EGit plug-in proposes a directory
outside your workspace.
Caution: Placing Git repositories directly in the workspace may cause performance issues
since the Git support in Eclipse then may need to scan a large number of files reachable
under the workspace.
The first time we create a repository we will create a general directory to hold all of the
repositories for our projects. Click on "Create" and then type in a parent directory name and
click "Finish".
After pressing the Finish button, the wizard displays the settings for your local Git repository.
Select the Finish button again to put your repository under Git version control.
You have created a local Git repository. The Git repository is in this case directly stored in the
specified folder in a .git folder.
• Note the decorator text "[…….. NO-HEAD]" behind the project name. This label
means that there is no branch (not even a master yet) for the project until we make
our first add and commit, the No-Head text will appear. Note also the question mark
decorator by files (*.java). This shows that the Java file is not yet under version
control.
To add files to our Git repository, we right-click Team > Add to Index on the project
name. The + decorator show that the project's files have been added to version control.
Git Repositories view
Eclipse Git has a Git repositories view which allow you to browse your repositories, add or
initialize local repositories or clone remote repositories, checkout projects, manage your
branches and much more.
The toolbar entries allow you to add an existing local Git repository to the view, clone a Git
repository and to create a new Git repository.
Check-off 1:
Edit your project and make a Commit. Reapet it and make a second commit.
Right-click on the Project name and choose Team > Show in History.
Copy the history records of your commit to your report.
To compare the code from our two commits, we first click the Compare Mode toggle
button in the History View. Then, we click (select) the master commit in the history list
and then double-click on source Java file in the resource list (bottom right panel in History
View). A new window will appear outlining the differences (changes) between the two
committals of code.
Check-off 2:
Copy the changes window and include it in your report.
ssh://git@github.com/
is the URI of GitHub.
The rest is the name of
your directory for the
repository.
• enter source and destination ref or select already existing branches from the
drop-down lists
• click Add Spec
This will transfer the newly defined mapping to the list Specifications for push