Java 无法使用jgit将中的本地目录克隆到远程github存储库

Java 无法使用jgit将中的本地目录克隆到远程github存储库,java,github-api,jgit,Java,Github Api,Jgit,我需要在本地计算机中创建一个github目录,我正在尝试使用远程github存储库克隆它。我尝试了多种方法使用jGit克隆repo,代码如下: package github; import org.eclipse.jgit.api.Git; import org.eclipse.jgit.api.errors.GitAPIException; import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.stor

我需要在本地计算机中创建一个github目录,我正在尝试使用远程github存储库克隆它。我尝试了多种方法使用jGit克隆repo,代码如下:

        package github;

import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.storage.file.FileRepositoryBuilder;
import org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider;
import java.io.File;
import java.io.IOException;
public class PushToRemoteRepository {

    private static final String REMOTE_URL = "https://github.com/syndy1989/Modify.git";

    public static void main(String[] args) throws IOException, GitAPIException {
        // prepare a new folder for the cloned repository
        File localPath = File.createTempFile("TestGitRepository", "");
        if(!localPath.delete()) {
            throw new IOException("Could not delete temporary file " + localPath);
        }
        UsernamePasswordCredentialsProvider upc = new UsernamePasswordCredentialsProvider("syndy1989", "xxxxx");
        // then clone
        System.out.println("Cloning from " + REMOTE_URL + " to " + localPath);
        Git result = Git.cloneRepository()
                .setURI(REMOTE_URL)
                .setDirectory(localPath)
                .setCredentialsProvider(upc)
                .call(); {

                    System.out.println(result);
                // now open the created repository
                FileRepositoryBuilder builder = new FileRepositoryBuilder();
                Repository repository = builder.setGitDir(localPath)
                        .readEnvironment() // scan environment GIT_* variables
                        .findGitDir() // scan up the file system tree
                        .build(); {
                    Git git = new Git(repository);{
                        git.push()
                                .call();
                    }

                    System.out.println("Pushed from repository: " + repository.getDirectory() + " to remote repository at " + REMOTE_URL);
                }
            }
        }
    }
我看到以下错误:

 Cloning from https://github.com/syndy1989/Modify.git to C:\Users\ADMINI~1\AppData\Local\Temp\2\TestGitRepository9138453641649961455
org.eclipse.jgit.api.Git@255b53dc
Exception in thread "main" org.eclipse.jgit.api.errors.TransportException: origin: not found.
    at org.eclipse.jgit.api.PushCommand.call(PushCommand.java:171)
    at github.PushToRemoteRepository.main(PushToRemoteRepository.java:47)
Caused by: org.eclipse.jgit.errors.NoRemoteRepositoryException: origin: not found.
    at org.eclipse.jgit.transport.TransportLocal$1.open(TransportLocal.java:131)
    at org.eclipse.jgit.transport.TransportBundleFile$1.open(TransportBundleFile.java:106)
    at org.eclipse.jgit.transport.Transport.open(Transport.java:556)
    at org.eclipse.jgit.transport.Transport.openAll(Transport.java:374)
    at org.eclipse.jgit.api.PushCommand.call(PushCommand.java:144)
    ... 1 more
我看到了一些使用JGit的示例和其他参考资料,如

使用的罐子:

<!-- https://mvnrepository.com/artifact/commons-io/commons-io -->
<dependency>
    <groupId>commons-io</groupId>
    <artifactId>commons-io</artifactId>
    <version>2.4</version>
</dependency>

<dependency>
    <groupId>org.eclipse.jgit</groupId>
    <artifactId>corg.eclipse.jgit</artifactId>
    <version>3.4.0.201406041058-rc3</version>
</dependency>

<dependency>
    <groupId>javax.validation</groupId>
    <artifactId>javax.validation</artifactId>
    <version>1.0.0.GA</version>
</dependency>

公地io
公地io
2.4
org.eclipse.jgit
corg.eclipse.jgit
3.4.0.201406041058-rc3
javax.validation
javax.validation
1.0.0.GA

raw.json文件(位于docker容器内的“C:\Git\raw.json”文件夹中)我所要做的就是将Git目录克隆到远程github存储库中,以自动方式使用java代码推送我的raw.json文件。请帮助我在本地机器上创建一个git目录,连接到远程git hub存储库&使用java将.json文件推送到远程存储库。提前感谢

您会看到
连接被拒绝:connect github.com
错误消息吗?检查您的internet连接是否有问题(您是否使用代理?)。您好@FlorianAlbrecht我已更新了我的代码和错误消息。我更改了代理设置。现在我得到了一个错误“org.eclipse.jgit.api.errors.TransportException:origin:not found”。关于这个问题的任何建议都会很有帮助。提前感谢为什么你要用FileRepositoryBuilder做所有的事情?只需按一下创建的
结果
对象……忘记我写的东西。你真的仔细阅读了你的例子吗??真正地一步一步地?整页?是的,我看了。我什么都试过了,就是不行。你能分享一下push和pull的java代码片段吗。那会有帮助的。