无法使用jgit将本地目录克隆到远程github存储库中
我需要在我的本地机器上创建一个github目录,并且试图用我的远程github repository克隆它。我尝试了很多方法来用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:UsersADMINI~1AppDataLocalTemp2TestGitRepository9138453641649961455
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和其他一些参考的例子,如http://www.codeaffine.com/2015/11/30/jgit-clone-repository/ https://github.com/centic9/jgit-cookbook/blob/master /src/main/java/org/dstadler/jgit/porcelain/CloneRemoteRepository.java
罐子的使用:
<!-- 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>
raw.json文件(位于Docker容器中的“C: Git raw.json”文件夹中)我所要做的就是将Git目录克隆到远程github存储库,以便使用java代码将我的raw.json文件推入一种自动的方式。 请帮助我在本地机器上创建一个git目录,连接到远程git hub存储库并使用java将.json文件推送到远程存储库。 提前致谢
链接地址: http://www.djcxy.com/p/45225.html上一篇: Unable to clone local directory in to remote github repository using jgit
下一篇: How do I get git to default to ssh and not https for new repositories