Version 2.1
Copyright © 2009 - 2010 Lars Vogel
30.08.2010
| Revision History | ||
|---|---|---|
| Revision 0.1 | 11.12.2009 | Lars Vogel |
| Created | ||
| Revision 0.2 - 2.1 | 12.12.2009 - 30.08.2010 | Lars Vogel |
| bug fixes and enhancements | ||
Table of Contents
Git is a distributed version control system written in C. For an introduction into Git and the usage of the command line for Git please see Git Tutorial . JGit is a library which implements Git in Java. EGit is an Eclipse Team provider for Git (using JGit). This article will describe the usage of EGit.
Install the EGit Eclipse plugin from http://download.eclipse.org/egit/updates . You may want to use the nightly update site as EGit is a fast moving target http://download.eclipse.org/egit/updates-nightly . Please see Eclipse Update manager for information on how to use the update manager.

Currently EGit and JGit are in an early phase of their development. Here are the issue which I would like to see.
If would also nice to have the option to re-start a repository from scratch. Bug report for disconnecting a repository and deleting the metadata. .
A nice to have feature would be if EGit could create a suitable default ".gitignore" file. See Bug report for default .gitignore".
The following explains how to create a repository for one project and shows how to checkout an exiting projects from a remote repository. The next chapter will demonstrate how to use EGit.
EGit has a repository view which allow you to browse your repositories, checkout projects and manage your branches.

Create a project "de.vogella.git.first". Create the following class.
package de.vogella.git.first;
public class GitTest {
/**
* @param args
*/
public static void main(String[] args) {
System.out.println("Git is fun");
}
}
Right click your project, select Team -> Share -> Git. Select the proposed line and press "Create repository". Press finish.

You have created a local Git repository.
Create the file ".gitignore" in your project with the following content. All files / directories which apply to the pattern described in this file will be ignored by git. In this example all files in the "bin" directory will be ignored.
bin
EGit allow to clone an existing project. We will use an Eclipse plugin as example. To learn more about accessing standard Eclipse coding please see Eclipse Source Code Guide .
Select File -> Import -> Git -> Git Repository.
Import for example the following project "git://dev.eclipse.org/org.eclipse.jface/org.eclipse.jface.snippets.git". You only have to paste the URL to the first line of the dialog, the rest will be filled out automatically.

After pressing next the system will allow you to import the existing branches. You should select at least "master".

The next dialog allow you to specify where the project should be copied to and which branch should be initially selected.

You get an additional import dialog.

You have checked to the project and can use the team Git operation on your project.
You may first create all projects under a common directory and then create a common repository for all projects in one go:
create the Eclipse projects e.g. a,b,c under a common directory e.g. d1
select all projects a,b,c - from context menu click "Team" > "Share Project" > "Git"
press "Next"
select all projects a,b,c
the wizard automatically moves up the default repository location to the parent folder d1since multiple projects have been selected
click "Create Repository" and click "Finish"
An alternative approach is described here: http://ekkescorner.wordpress.com/blog-series/git-mercurial/workflow-create-multi-project-repositories-egit/
Once you have placed a project under version control you can start using team operations on your project. The team operations are available via right mouse click on your project. You can:
Select "Team" -> "Add", on the project node to add all files to version control.
Select "Team" -> "Commit", to commit your changes to the local Git repository.
Select "Team" -> "Branch" to create and to switch between branches.
Select "Team" -> "Push" to push your change to a remote Git repository (see the GitHub chapter).
"Team" -> "Tag" allows you to create and manage tags.
EGit supports currently fast-forward merge. Fast-forward merge allows to add the changes of one branch into another if this branch has not been changed. Select "Team" -> "Merge" to perform this opertation.
Github is a popular hosting provider for Git projects and if you repository is public to everyone Github hosting is free. To use GitHub create an account on the Github Website . During the sign-up you will be asked to provide a "passphase". This "passphase" is later needed to push to Github from your local repository.
Create a new repository on Github, e.g. "de.vogella.git.github".

After creation of your new repository Github tells you what to do if you would inport via the command line. As we are going to use EGit we can ignore this information.
Create a new project "de.vogella.git.github" and put it under version control. Right-mouse click on your project and select "Team" -> "Push". A dialog pops up. Maintain the following data. Adjust the hightlighted line so that you are using your user and your project name.
git+ssh://git@github.com/vogella/de.vogella.git.github

Maintain your passphase which you maintained during the Github setup.

Select your branch (you should currently only have master if you followed my tutorial), press "Add all branches spec" and select next.

Press finish.

If you now select your github Dashboard and then your project you should see the commited files.

Use the same URI you use to push to Github to clone the project into another workspace.
EGit is self-hosted on git://egit.eclipse.org . You can clone the EGit code from the repository using EGit using the following URL git://egit.eclipse.org/jgit.git and git://egit.eclipse.org/egit.git .
You also need some libraries from Orbit. See Libraries from Orbit for getting these libraries.
Thank you for practicing with this tutorial.
I maintain this tutorial in my private time. If you like the information please help me by using flattr or donating or by
|
Before posting questions, please see the vogella FAQ . If you have questions or find an error in this article please use the www.vogella.de Google Group . I have created a short list how to create good questions which might also help you. .
http://wiki.eclipse.org/EGit/User_Guide EGit User Guide
http://wiki.eclipse.org/EGit/Contributor_Guide EGit contributor guide