JGit authentification with Http token

benjamin wieser profile picture
Benjamin Wieser
30/01/2025

In this guide I will show you how to set up JGIT using a http token:

Why use HTTP?

HTTP is useful for occasional Git access, environments where SSH is blocked, or cloud-based CI/CD services using personal access tokens. It requires less setup and works well when managing multiple machines without SSH keys. While less secure and convenient for frequent use, it remains a simple alternative where SSH is impractical.

HTTP Configuration

First of all we need to import the maven dependencies:

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

Than we can clone the repository:

var repository = "https://github.com/eclipse-jgit/jgit.git";
var directory = "./directory";
var directory = "./directory";
var token = "ThisIsTheToken

Git.cloneRepository()
	​.setURI(repository)
	​.setCredentialsProvider(new UsernamePasswordCredentialsProvider("token", token))
	​.setDirectory(new File(directory))
	​​.call();

Überzeugt? Kontaktieren Sie uns!

Schicken Sie uns einfach eine Email an office@vorstieg.eu oder füllen Sie das folgende Kontakt-Formular aus: