git.checkout().setCreateBranch(true).setName("stable")
.setUpstreamMode(SetupUpstreamMode.SET_UPSTREAM)
.setStartPoint("origin/stable").call();
Returns:
the newly created branch
Throws:
RefAlreadyExistsException
- when trying to create (without force) a branch with a name
that already exists
RefNotFoundException
- if the start point or branch can not be found
InvalidRefNameException
- if the provided name is
null
or otherwise
invalid
CheckoutConflictException
- if the checkout results in a conflict
GitAPIException
- or subclass thereof when an error occurs
public
CheckoutCommand
addPath
(
String
path)
Add a single path to the list of paths to check out. To check out all
paths, use
setAllPaths(boolean)
.
If this option is set, neither the
setCreateBranch(boolean)
nor
setName(String)
option is considered. In other words, these
options are exclusive.
Parameters:
path
- path to update in the working tree and index
Returns:
this
Set whether to checkout all paths.
This options should be used when you want to do a path checkout on the
entire repository and so calling
addPath(String)
is not possible
since empty paths are not allowed.
If this option is set, neither the
setCreateBranch(boolean)
nor
setName(String)
option is considered. In other words, these
options are exclusive.
Parameters:
all
-
true
to checkout all paths,
false
otherwise
Returns:
this
Since:
public
CheckoutCommand
setName
(
String
name)
Specify the name of the branch or commit to check out, or the new branch
name.
When only checking out paths and not switching branches, use
setStartPoint(String)
or
setStartPoint(RevCommit)
to
specify from which branch or commit to check out files.
When
setCreateBranch(boolean)
is set to
true
, use
this method to set the name of the new branch to create and
setStartPoint(String)
or
setStartPoint(RevCommit)
to
specify the start point of the branch.
Parameters:
name
- the name of the branch or commit
Returns:
this instance
public
CheckoutCommand
setCreateBranch
(boolean createBranch)
Specify whether to create a new branch.
If
true
is used, the name of the new branch must be set
using
setName(String)
. The commit at which to start the new
branch can be set using
setStartPoint(String)
or
setStartPoint(RevCommit)
; if not specified, HEAD is used. Also
see
setUpstreamMode(org.eclipse.jgit.api.CreateBranchCommand.SetupUpstreamMode)
for setting up branch tracking.
Parameters:
createBranch
- if
true
a branch will be created as part of the
checkout and set to the specified start point
Returns:
this instance
public
CheckoutCommand
setForce
(boolean force)
Specify to force the ref update in case of a branch switch.
Parameters:
force
- if
true
and the branch with the given name
already exists, the start-point of an existing branch will be
set to a new start-point; if false, the existing branch will
not be changed
Returns:
this instance
public
CheckoutCommand
setStartPoint
(
String
startPoint)
Set the name of the commit that should be checked out.
When checking out files and this is not specified or
null
,
the index is used.
When creating a new branch, this will be used as the start point. If not
specified or
null
, the current HEAD is used.
Parameters:
startPoint
- commit name to check out
Returns:
this instance
public
CheckoutCommand
setStartPoint
(
RevCommit
startCommit)
Set the commit that should be checked out.
When creating a new branch, this will be used as the start point. If not
specified or
null
, the current HEAD is used.
When checking out files and this is not specified or
null
,
the index is used.
Parameters:
startCommit
- commit to check out
Returns:
this instance
setUpstreamMode
public
CheckoutCommand
setUpstreamMode
(
CreateBranchCommand.SetupUpstreamMode
mode)
When creating a branch with
setCreateBranch(boolean)
, this can
be used to configure branch tracking.
Parameters:
mode
- corresponds to the --track/--no-track options; may be
Returns:
this instance
public
CheckoutCommand
setStage
(
CheckoutCommand.Stage
stage)
When checking out the index, check out the specified stage (ours or
theirs) for unmerged paths.
This can not be used when checking out a branch, only when checking out
the index.
Parameters:
stage
- the stage to check out
Returns:
this