Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Working with a remote repository in JGit

Tags:

java

git

jgit

I am working on a project where we have to use JGit. I have a problem when I try to work with a remote git repository (the git that is not cloned in my local device) I receive the following exception:

No HEAD exists and no explicit starting revision was specified

If I clone the repository it works well, but repositories are quite big and I cannot clone it because of project requirements. Is there a way how to work with remote repositories? I do only simple read operations.

like image 360
user3304071 Avatar asked May 09 '17 09:05

user3304071


People also ask

How do I start working on a remote repository?

The first command you need in order to start using a remote repository is the git clone command. To run the command, after “clone”, put the URL to the server's . git file. Services like GitHub will give you the repository URL to copy in order to clone a repository.

What is JGit repository in Git?

A Git repository is represented in JGit through the Repository class that can be viewed as a handle to a repository. With a Repository instance, you can create JGit commands (through the Git factory class), gain access to configuration settings, resolve refs, etc.

How to manipulate a remote Git repository?

Git is a distributed version control system and as such is not designed to manipulate a remote repository directly. To manipulate a remote repository, you have to clone it first. Now you can make modifications to the local copy, like commit new or changed files, create branches or tags, etc.

How do I move a git repository to another location?

The first command will add an origin (a remote repository) to your local Git and the second one will verify the added repository URL. Next, it's time to check and pull all the changes on the remote repository to the local one to get them both aligned.

What is the difference between JGit and native Git?

Unfortunately JGit’s status implementation slightly differs from native Git in that it doesn’t complain if there is no repository. This makes it necessary to check for an existing HEAD ref which indicates that there actually is a repository.


1 Answers

In order to access the history of a Git repository you need to clone it first. The clone may be bare if you are not interested in the working dir, but a clone is required.

Git allows to create a shallow clone that includes only the history up to a specified depth, however JGit still lacks support for shallow clones: https://bugs.eclipse.org/bugs/show_bug.cgi?id=475615

like image 85
Rüdiger Herrmann Avatar answered Sep 18 '22 15:09

Rüdiger Herrmann