Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EGit / JGit » How to Create New Local branch and push that to remote and set upstream(Need to create a localbranch and push that branch to remote(which is not present in remote) and then set upstream)
How to Create New Local branch and push that to remote and set upstream [message #1768069] Thu, 13 July 2017 11:35 Go to next message
Jothivignesh Chinnadurai is currently offline Jothivignesh ChinnaduraiFriend
Messages: 1
Registered: July 2017
Junior Member
I am going to dynamically create local branches(like Hotfix_Test1, Hotfix_Test2 each at different time) and push it to remote.
These branches should contain the source available in a branch called Release which is another local.
Release is already pushed to remote from local using git commands
git checkout -b Release git push
git push --set-upstream origin Release
I create a git object and trying the following code to create hotfix branches dynamically.

Kindly check the java file attached

when the execution comes to this line
'createBranchCommand.setUpstreamMode(SetupUpstreamMode.SET_UPSTREAM);'
it is throwing exception

java.lang.IllegalStateException: Command org.eclipse.jgit.api.CreateBranchCommand was called in the wrong state
i dont know wats the mistake. Kindly help with the error.
Re: How to Create New Local branch and push that to remote and set upstream [message #1768147 is a reply to message #1768069] Fri, 14 July 2017 07:29 Go to previous message
Christian Halstrick is currently offline Christian HalstrickFriend
Messages: 274
Registered: July 2009
Senior Member
You have one instance of CreateBranchCommand but you are trying to call call() multiple times. That's not supported. Each instance of a Command should only be used for one invocation. Do something like:

           /* Creating Hotfix Branch */
           git.branchCreate().setName("hotfix_" + releaseVersion).call();

            /*
             * Pushing Hotfix Branch to remote note that the hotfix is not present in remote
             */
            pushCommand = git.push().setRemote("origin").setRefSpecs(new RefSpec("hotfix_" + releaseVersion + ":hotfix_" + releaseVersion)).call();

            /* Trying to set upstream for newly created hotfix branch */
            git.branchCreate().setUpstreamMode(SetupUpstreamMode.SET_UPSTREAM).setStartPoint("origin/" + "hotfix_" + releaseVersion).createBranchCommand.setForce(true).call();
...


Ciao
Chris
Previous Topic:Keyboard Shortcuts to Navigate Through Changes in Egit
Next Topic:Problems with .target file and JGit being updated
Goto Forum:
  


Current Time: Fri Apr 19 19:41:13 GMT 2024

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

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

Back to the top