Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EGit » JGit: Push to specific branch
JGit: Push to specific branch [message #1066719] Thu, 04 July 2013 05:20 Go to next message
Tim Braun is currently offline Tim BraunFriend
Messages: 8
Registered: July 2013
Junior Member
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 18:02 Go to previous message
Tim Braun is currently offline Tim BraunFriend
Messages: 8
Registered: July 2013
Junior Member
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 18:02]

Report message to a moderator

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


Current Time: Thu Nov 27 22:22:52 GMT 2014

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

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