Eclipse EGit Plugin, Part 2

By Dmitry Churbanov on

In the previous post we discussed how to import remote Git repository. Now let’s look what Git commands are available in EGit plugin. EGit plugin is still not completely ready and does not support all Git commands. You can watch “Understanding and Using Git at Eclipse” webinar to learn what is ready and what the plans are.

In this post I will continue to use the same remote repository which was used in the previous post.

Basic operations

In the first post about Git we discussed the basic Git operations. Now let’s see how you can do the same using EGit plugin.

Add files

Create com.churbanov.tutorial.egit package and the following two classes:

1
2
3
4
5
6
7
8
9
10
11
12
13
package com.churbanov.tutorial.egit;

/**
 * Represents workshop where different works with cars, boats
 * and other vehicles can be done.
 *
 * @author Dmitry Churbanov
 */
public class Workshop {
  public static void main(String[] args) {
    System.out.println("Welcome to our Workshop!");
  }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
package com.churbanov.tutorial.egit;

public class Part {
  private Long id;
  private String name;

  public Long getId() {
    return id;
  }
  public void setId(Long id) {
    this.id = id;
  }
  public String getName() {
    return name;
  }
  public void setName(String name) {
    this.name = name;
  }
}

Now we need to tell Git to start tracking just added classes. To do so, we select Part.java and Workshop.java classes in eclipse package explorer -> Team -> Add

Commit changes

To commit changes select Team -> Commit. The “Commit Changes” window will pop up and you will need to enter commit message and select what files you want to commit or unselect the files you don’t want to commit. Press “Commit” and all the changes will be committed.

After commit you can see that Workshop.java and Part.java files icons are changed in package explorer.

Push changes

To push the changes to the remote repository select Team -> Push. The current version of EGit (0.8.4) has a bug and in most cases push will not work (more is here). There is a small workaround (see Comment #2 in that bug discussion), but it still didn’t work for me on my Ubuntu 10.04. So I did it in command line. (Just after I had published this post I found that EGit doesn’t support pushing via https. More is here.)

Other useful things

The other useful things which you can do with EGit are:

Tags

Select “eclipse_git” project folder -> Team -> Tag. Enter tag name, tag message and press OK button.

History of a particular resource

Select any resource (project, package, class, etc) -> Show In -> History. And you can see all the history of the selected resource in the Git repository.

Branches

If you want to make a branch, select “eclipse_git” project folder -> Team -> Branch.

In the appeared window select “master” in the “Local Branches” category -> press “New branch” button -> enter new branch name -> press OK button. New branch will be created.

To switch to the new branch select “eclipse_egit” project folder -> Team -> Branch -> select the branch you want to switch to -> press Checkout button.

Useful links

Tags: eclipse, egit, git


Comments