CtrlK
BlogDocsLog inGet started
Tessl Logo

finkel/jgit

JGit documentation and API reference with code examples

92

1.09x
Quality

Pending

Does it follow best practices?

Impact

92%

1.09x

Average score across 10 eval scenarios

SecuritybySnyk

Pending

The risk profile of this skill

Overview
Eval results
Files

JGit - Java Git Implementation

JGit is a pure Java library implementing the Git version control system. This tile provides comprehensive documentation and code examples for using JGit in Java applications.

Overview

JGit is a full-featured Git implementation in Java, used by tools like EGit (Eclipse Git plugin), Gerrit, and Gitiles. It provides both high-level "porcelain" commands (similar to Git CLI) and low-level APIs for direct repository manipulation.

Key Features:

  • Pure Java implementation
  • No native dependencies
  • Complete Git protocol support (file, HTTP, SSH, Git)
  • Memory-efficient repository access
  • Extensible API

Installation

Add JGit as a dependency in your project:

Maven

<dependency>
    <groupId>org.eclipse.jgit</groupId>
    <artifactId>org.eclipse.jgit</artifactId>
    <version>7.6.0.202603022253-r</version>
</dependency>

Gradle

implementation 'org.eclipse.jgit:org.eclipse.jgit:7.6.0.202603022253-r'

Quick Start

Opening a Repository

import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.storage.file.FileRepositoryBuilder;
import java.io.File;

public class OpenRepositoryExample {
    public static void main(String[] args) throws Exception {
        FileRepositoryBuilder builder = new FileRepositoryBuilder();
        try (Repository repository = builder
                .setGitDir(new File("/path/to/.git"))
                .readEnvironment()
                .findGitDir()
                .build()) {
            System.out.println("Repository opened: " + repository.getDirectory());
        }
    }
}

Table of Contents

  1. Repository Basics
  2. Porcelain Commands
  3. Remote Operations
  4. Low-level API
  5. Common Patterns

Repository Structure

JGit provides two main API layers:

  • Porcelain: High-level commands similar to Git CLI (e.g., git add, git commit, git clone)
  • Plumbing: Low-level APIs for direct repository manipulation

Available Snippets (JGit Cookbook)

The JGit Cookbook provides numerous ready-to-run code snippets:

General Repository Handling

  • Open an existing repository
  • Create a new repository

Porcelain Commands

  • Initialize a new repository
  • Add files to index
  • Commit files
  • List commits (log)
  • List tags and branches
  • Create/delete branches and tags
  • Show diffs between commits/branches
  • Show repository status
  • Create archives
  • Blame (line attribution)
  • Add/list notes
  • Clean untracked files
  • Stash operations
  • Garbage collection
  • Merge changes

Remote Repository Operations

  • Clone remote repositories (HTTP, SSH)
  • List remote references
  • Fetch from remotes (with prune)
  • Push to remotes
  • Rebase onto upstream
  • In-memory repository cloning
  • Checkout GitHub pull requests
  • Set remote tracking branches

Low-level API

  • Get refs from names
  • Parse commit, tree, tag objects
  • Read blob contents
  • Resolve complex references
  • Walk commit graphs
  • Read file from specific commit
  • List configured remotes
  • Read user configuration
  • Get file attributes
  • Check branch tracking status
  • Check merge status
  • List files in commits/tags
  • Walk tree recursively/non-recursively

GitServlet

  • Standalone HTTP Git server example

Getting Help

Workspace
finkel
Visibility
Public
Created
Last updated
Describes
mavenpkg:maven/org.eclipse.jgit/org.eclipse.jgit
Publish Source
CLI
Badge
finkel/jgit badge