I have two branches on github: master and development. I want to push a newly created file to the development branch.
String user = "user";
String password = "password";
String localPath = "local";
String remotePath = "https://github.com/some/git.git";
Git.cloneRepository().setBranch("refs/heads/development").setURI(remotePath).setDirectory(new File(localPath)).call();
Git localGit = Git.open(new File(localPath));
localGit.checkout().setName("origin/development").setUpstreamMode(SetupUpstreamMode.TRACK).call();
new File("local/test").createNewFile();
localGit.add().addFilepattern(".").call();
localGit.commit().setMessage("message").call();
localGit.push().setCredentialsProvider(new UsernamePasswordCredentialsProvider(user, password)).call();
What I get is a
TransportException: Nothing to push.
What's the problem there?
Update: I could make it work by removing the checkout command. As the clone already checks out the specified branch, which wasn't clear to me before.