Baike.dev
All toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
J

jgit-cookbook

> 开发工具
Open source

Provides examples and code snippets for the JGit Java Git implementation

1.8K stars0 likes0 views
WebsiteGitHub

About

Provides examples and code snippets for the JGit Java Git implementation

jgit-cookbook

Provides examples and code snippets for the JGit Java Git implementation.

The JGit framework is rich and diverse, it has two layers, a low-level api and a higher-level set of porcelain commands. This can be a bit intimidating at first as there are lots of classes, some of which are not relevant for most tasks.

This project tries to provide a collection of ready-to-run snippets which provide a quick start for building functionality using JGit.

Please make sure to take a look at the nicely written introduction and also use the existing JavaDoc and the User Guide as well, as they are well done and provide detailed information and a general overview of JGit respectively.

Note: Please use sites such as http://stackoverflow.com for general questions about JGit usage, not issues in this project. Issues should be used for problems with snippets and suggestions of missing snippets. Snippets from good answers on stackoverflow can then be included here, naturally.

Getting started

Install JDK

You will need at least JDK 17 for JGit 7.0 and newer.

Grab it
git clone https://github.com/centic9/jgit-cookbook.git
Build it and create Eclipse project files When using Maven
mvn dependency:sources eclipse:eclipse package
When using Gradle
./gradlew eclipse check

Run it

Each snippet is a small standalone Java application, so you can simply  
import the project into your favourite IDE and execute the snippets there.

Currently the following snippets are available

General Repository handling
  • Open an existing repository
  • Create a new repository
Porcelain commands
  • Initialize a new repository
  • Add a new file to the index
  • Commit a file to an existing repository
  • Commit all changes
  • List commits (i.e. Log)
  • Find all commits that touch files matching a pattern
  • List all tags in a repository
  • List all branches in a repository
  • List all commits in a repository
  • List uncommitted changes of a repository
  • Create and delete branches
  • Create and delete tags
  • List all tags applied on a branch
  • Revert a modified tracked file back to its original state in most recent commit
  • Return diff between two branches
  • Show diff of changes to a file between two revs
  • Show diff of changes to all files between two commits
  • Show diff of changes to a file between two commits when the file has been renamed
  • Show Status
  • Store contents of branch into a compressed file
  • Write contents of branch into a compressed file using a custom archive format
  • Blame, i.e. find out which commit changed specific lines in a file
  • Add and list Notes attached to commits
  • List available Notes
  • Clean all untracked files
  • Create, list, apply and drop stashes
  • Run garbage collection
  • Blame, i.e. retrieve information who last changed which line in a file
  • Merge changes from a branch
  • List changed files between two commits
  • List changed files in index
  • List changed files in checkout
Commands working with remote repositories
  • Clone a remote repository into a new local directory
  • Clone a remote repository via Apache SSHD
  • Iterate remote references in a repository
  • List remote heads/tags without a local clone
  • Fetch from remote repositories
  • Fetch from remote repositories and use 'prune' to remove outdated remote branches/tags
  • Fetch from remote repositories via SSH protocol
  • Clone a remote repository via SSH protocol and username/password credentials
  • Rebase onto an upstream branch
  • Using InMemoryRepository to clone a Git repo in-memory and work from there
  • Checkout a PR from GitHub
  • Push to a remote repository
  • Set remote tracking branch
Low-level API
  • Get the SHA-1 ref from a name, e.g. refs/heads/master
  • Get the commit-object from a name or a SHA-1
  • Get the commit-message
  • Get the tree-object from a commit-object, name or SHA-1
  • Read the contents of a file/blob
  • Get the tag-object from a name or a SHA-1
  • Resolve complex references, e.g. HEAD^^ to a SHA-1
  • Iterate over the commits on a branch
  • Iterate over a range of commits
  • Read contents of a specific file from a specific commit
  • List remotes configured for the current repository
  • Print out user information from Git
  • Read file attributes, e.g. executable state, file or directory, size, ...
  • Use class BranchTrackingStatus to retrieve number of commits ahead/behind compared to remote branches
  • [Check if commits on other branc

GitHub Issues· 0 open

View all on GitHub

No open issues yet, or sync has not completed.

Highlights

  • •Open an existing repository
  • •Create a new repository
  • •Initialize a new repository
  • •Add a new file to the index
  • •Commit a file to an existing repository
  • •Commit all changes
  • •List commits (i.e. Log)
  • •Find all commits that touch files matching a pattern
  • •List all tags in a repository
  • •List all branches in a repository

> Tags

Javagitjava-gitjgitjgit-cookbook

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category开发工具
PricingOpen source

> Related tools

V
VS Code
流行的开源代码编辑器
G
Git
分布式版本控制系统
V
Vite
下一代前端构建工具