Class Git

  • All Implemented Interfaces:
    AutoCloseable

    public class Git
    extends Object
    implements AutoCloseable
    Offers a "GitPorcelain"-like API to interact with a git repository.

    The GitPorcelain commands are described in the Git Documentation.

    This class only offers methods to construct so-called command classes. Each GitPorcelain command is represented by one command class.
    Example: this class offers a commit() method returning an instance of the CommitCommand class. The CommitCommand class has setters for all the arguments and options. The CommitCommand class also has a call method to actually execute the commit. The following code show's how to do a simple commit:

     Git git = new Git(myRepo);
     git.commit().setMessage("Fix393").setAuthor(developerIdent).call();
     
    All mandatory parameters for commands have to be specified in the methods of this class, the optional parameters have to be specified by the setter-methods of the Command class.

    This class is intended to be used internally (e.g. by JGit tests) or by external components (EGit, third-party tools) when they need exactly the functionality of a GitPorcelain command. There are use-cases where this class is not optimal and where you should use the more low-level JGit classes. The methods in this class may for example offer too much functionality or they offer the functionality with the wrong arguments.