I\'m using JGit to checkout a remote tracking branch.
Git binrepository = cloneCmd.call()
CheckoutCommand checkoutC
You have to use setCreateBranch to create a branch:
Ref ref = git.checkout().
setCreateBranch(true).
setName("branchName").
setUpstreamMode(CreateBranchCommand.SetupUpstreamMode.TRACK).
setStartPoint("origin/" + branchName).
call();
Your first command was the equivalent of git checkout origin/mybranch.
(Edit: I submitted a patch to JGit to improve the documentation of CheckoutCommand: https://git.eclipse.org/r/8259)