JGit: Checkout a remote branch

前端 未结 4 1540
滥情空心
滥情空心 2020-12-16 10:46

I\'m using JGit to checkout a remote tracking branch.

Git binrepository = cloneCmd.call()

CheckoutCommand checkoutC         


        
4条回答
  •  爱一瞬间的悲伤
    2020-12-16 10:58

    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)

提交回复
热议问题