I searched through Google, forums and JGit user guide but couldn't find how to connect to a distant repository with the API. Anyone has an example or just an idea on how to do that?
Thanks for your help.
I searched through Google, forums and JGit user guide but couldn't find how to connect to a distant repository with the API. Anyone has an example or just an idea on how to do that?
Thanks for your help.
Currently, JGit 2.0.0-SNAPSHOT does only offer
org.eclipse.jgit.storage.file.FileRepository
org.eclipse.jgit.storage.dfs.InMemoryRepository
concrete Repository
classes, meaning that since org.eclipse.jgit.api.Git
takes a Repository
, it is not possible to work remotely. Since Git by itself is not designed to operate remotely in the way I think you mean, I doubt we will see such a feature any time soon.
MORE ON THAT:
Consequently, you will need to clone locally. You do that by issuing
Git.cloneRepository()
.setURI(myRemoteURIString)
.setDirectory(new File(myLocalPathString))
.call();
However, for reasons of consistency in Git you should clone a bare repository only, so a non-bare repository in a remote location, while not technically, is practically inaccessible.
I am not sure I understand the question since Git is made for accessing other repositories, this is what is meant by "Git is distributed".
If you want to connect to ONE distant repository, then yeah you should clone it.
I don't know if that is what you are looking for, but you can also use multiple remotes. Adding one more is done with Git using git remote add <remote_name> <remote_uri>
. As for Jgit, I unfortunately can't remember the code to do it simply, but you can figure this out.
At least it's possible by modifying the configuration, calling getConfig()
from a Repository object and then calling setString(...)
on it - don't forget to save the configuration in the end. But before modifying the configuration, I think you should first get to know more about Git and JGit.
I recommend you to read more about it, and play a bit with your repository. Take a look at this article : http://caiustheory.com/adding-a-remote-to-existing-git-repo . Another one that will help you down the road is How do I do the equivalent of “git remote update” with jgit?
Maybe someone else knows exactly which commands to run and can help.