Am trying to push my local directory to Github with java,getting below exception.but i can able to create the repository and can able to search the repository.but not able to push list of files(complete directory)
static void pushRepo() {
try {
String localPath = "D:\\path\\to\\directory";
Repository localRepo = new FileRepository(localPath);
Git git = new Git(localRepo);
// add remote repo:
RemoteAddCommand remoteAddCommand = git.remoteAdd();
remoteAddCommand.setName("origin");
//remoteAddCommand.setUri(new URIish("https://github.com/.git"));//url corretected
remoteAddCommand.setUri(new URIish("git@github/api2.git"));//url corretected
// you can add more settings here if needed
remoteAddCommand.call();
// push to remote:
PushCommand pushCommand = git.push();
pushCommand.setCredentialsProvider(new UsernamePasswordCredentialsProvider("abcd", "abcd123"));
// you can add more settings here if needed
pushCommand.call();
} catch (Exception e) {
e.printStackTrace();
}
}
Exception:
org.eclipse.jgit.api.errors.TransportException: Nothing to push.
at org.eclipse.jgit.api.PushCommand.call(PushCommand.java:180)
at stash.StashClone.pushRepo(StashClone.java:71)
at stash.StashClone.main(StashClone.java:30)
Caused by: org.eclipse.jgit.errors.TransportException: Nothing to push.
at org.eclipse.jgit.transport.Transport.push(Transport.java:1298)
at org.eclipse.jgit.api.PushCommand.call(PushCommand.java:169)
... 2 more