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.
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.
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.
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.
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With