Skip to main content



      Home
Home » Eclipse Projects » EGit / JGit » JGit: Push to specific branch
JGit: Push to specific branch [message #1066719] Thu, 04 July 2013 01:20 Go to next message
Eclipse UserFriend
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 = "..."; //here would be the url to github but i am not allowed to post a link in the forum
    Git.cloneRepository().setBranch("development").setURI(remotePath).setDirectory(new File(localPath)).call();
    Git localGit = Git.open(new File(localPath));
    localGit.checkout().setName("origin/development").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? How can I make this work?
Re: JGit: Push to specific branch [message #1066847 is a reply to message #1066719] Thu, 04 July 2013 14:02 Go to previous message
Eclipse UserFriend
never mind, I could finally make it work.

The checkout wasn't necessary, as the clone already checks out the specified branch. For some reason, that is not clear to me, an additional checkout would detach the HEAD which causes push to fail.

[Updated on: Thu, 04 July 2013 14:02] by Moderator

Previous Topic:Cannot merge now
Next Topic:Simple Git client using JGit has trouble with fetch/pull
Goto Forum:
  


Current Time: Fri Jul 04 23:51:44 EDT 2025

Powered by FUDForum. Page generated in 0.05010 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top