[英]JGit: How to fix NoRemoteRepositoryException while creating Git Repository and pushing it to GitHub?
Using JGit, I want to create a NEW repository and push it to GitHub. 使用JGit,我想创建一个新的存储库并将其推送到GitHub。 I am getting NoRemoteRepositoryException.
我收到了NoRemoteRepositoryException。 Please help.
请帮忙。 What am I missing in my code?
我的代码中缺少什么?
private void createNewRepository(Task task, String path) {
File directory = new File(path);
try {
Git git = Git.init().setDirectory(directory).call();
git.add().addFilepattern( "readme.txt" ).call();
git.commit().setMessage( "Create readme file" ).call();
RemoteAddCommand remoteAddCommand = git.remoteAdd();
remoteAddCommand.setName("origin");
remoteAddCommand.setUri(new URIish(task.getVcUrl()));
remoteAddCommand.call();
CredentialsProvider credentialsProvider = new UsernamePasswordCredentialsProvider(task.getVcUsername(), task.getVcPassword());
git.push().setCredentialsProvider(credentialsProvider).
setRemote("origin").setPushAll().setForce(true).call();
} catch (GitAPIException ex) {
logger.warn(ex.getLocalizedMessage(), ex);
taskLogger.get().append(ex.getLocalizedMessage()).append("\n");
} catch (URISyntaxException e) {
e.printStackTrace();
}
}
The error stacktrace is 错误堆栈跟踪为
Caused by: org.eclipse.jgit.errors.NoRemoteRepositoryException:
http://github.com/AAA/Orgtest_sd3:
https://github.com/AAA/Orgtest_sd3/info/refs?service=git-receive-pack not
found
at
org.eclipse.jgit.transport.TransportHttp.connect(TransportHttp.java:520)
at
org.eclipse.jgit.transport.TransportHttp.openPush(TransportHttp.java:440)
at org.eclipse.jgit.transport.PushProcess.execute(PushProcess.java:160)
at org.eclipse.jgit.transport.Transport.push(Transport.java:1344)
at org.eclipse.jgit.api.PushCommand.call(PushCommand.java:169)
You cannot create a new remote repository from your local host, neither with JGit nor with native Git. 您不能使用JGit或本机Git从本地主机创建新的远程存储库。
You'll have to first create a repository on the remote host, then you can clone, fetch, and push from/to this repository. 您必须首先在远程主机上创建一个存储库,然后才能从该存储库克隆,获取和推送。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.