| Java, Eclipse and Web programming Tutorials |
Version 1.5
Copyright © 2009 - 2010 Lars Vogel
02.03.2010
| Revision History | ||
|---|---|---|
| Revision 0.1 | 11.12.2009 | Lars Vogel |
| Splitted from http://www.vogella.de/articles/Git/article.html | ||
| Revision 0.2 | 12.12.2009 | Lars Vogel |
| Chapter on bugs | ||
| Revision 0.3 | 16.12.2009 | Lars Vogel |
| Getting EGit | ||
| Revision 0.4 | 22.12.2009 | Lars Vogel |
| Added bug for http via proxy checkout | ||
| Revision 0.5 | 03.01.2010 | Lars Vogel |
| Added info for HTTP checkout | ||
| Revision 0.6 | 26.01.2010 | Lars Vogel |
| New update site for EGit | ||
| Revision 0.7 | 06.02.2010 | Lars Vogel |
| Github | ||
| Revision 0.8 | 10.02.2010 | Lars Vogel |
| how to make team operations availabe | ||
| Revision 0.9 | 11.02.2010 | Lars Vogel |
| how to get Egit via Egit | ||
| Revision 1.0 | 12.02.2010 | Lars Vogel |
| How to use GitHub with EGit | ||
| Revision 1.1 | 15.02.2010 | Lars Vogel |
| Updated due to fixed bug 298027 | ||
| Revision 1.2 | 16.02.2010 | Lars Vogel |
| Added team operations | ||
| Revision 1.3 | 17.02.2010 | Lars Vogel |
| Change order of section | ||
| Revision 1.4 | 29.02.2010 | Lars Vogel |
| added link to multiple repository description from Ekke | ||
| Revision 1.5 | 02.03.2010 | Lars Vogel |
| Added .gitignore, improved Github description, Mylyn connector | ||
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 . 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 are critical for me.
Currently EGit does not support the creation of patches. Please see Bug: EGit should be able to create patches
Http checkout behind a proxy does not work Bug report for proxy support .
Branching has also some issues. Braching creates inconsistency
In addition to these a few usuabilty enhancements would be nice.
EGit should be able to maintain and remember the user settings (user credentials) Bug report and Bug report
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".
It would be great if we could add origins via the EGit plugin Adding origin via EGit
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.
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.
The following blog entry describes how to create several projects in one git repository: 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 to version control" 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.
Github is a popular hosting provider for Git projects. To use Github go to their webpage and create an account. Public trees are hosted by Github for free.
If you do not yet have an account sign-up now for Github. 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. Call it "de.vogella.git.github"


Github is nice enough to tell you what to do if you work on the command line. Do not follow the instructions.
Global setup:
Download and install Git
git config --global user.name "Lars Vogel"
git config --global user.email youremail...
Next steps:
mkdir de.vogella.git.github
cd de.vogella.git.github
git init
touch README
git add README
git commit -m 'first commit'
git remote add origin git@github.com:vogella/de.vogella.git.github.git
git push origin master
Existing Git Repo?
cd existing_git_repo
git remote add origin git@github.com:vogella/de.vogella.git.github.git
git push origin master
Importing a Subversion Repo?
Click here
When you're done:
Continue
Create a new project in Eclipse with the name "de.vogella.git.github". Create a new local repository for this project and commit to this local repository.
Right-mouse click on your project and select "Team" -> "Push to". Select the proposed line and press "Create repository" and afterwards select "Finish". Maintain the following data. Adjust the first 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.

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.
Please note that I maintain this website in my private time. If you like the information I'm providing please help me by donating.For questions and discussion around this article please use the www.vogella.de Google Group. Also if you note an error in this article please post the error and if possible the correction to the Group.
I believe the following is a very good guideline for asking questions in general and also for the Google group How To Ask Questions The Smart Way.
http://wiki.eclipse.org/EGit/User_Guide EGit User Guide
http://wiki.eclipse.org/EGit/Contributor_Guide EGit contributor guide
Git in 5 Minutes by Scott Paul Robertson
http://progit.org/ Free Git book
https://dev.eclipse.org/mailman/listinfo/egit-dev eGit Mailing list
http://www.ibm.com/developerworks/opensource/library/l-git-subversion-1/index.html Git Intro for subversion users by Teodor Zlatanov
http://alblue.blogspot.com/2010/02/git-for-eclipse-users.html Git for Eclipse users by Alex Blewitt