Main Content

switchBranch

Switch Git branch

Since R2023b

    Description

    example

    branchDetails = switchBranch(repo,name) switches to the specified local branch name in the Git™ repository repo.

    Examples

    collapse all

    Navigate to your repository folder and create a repository object.

    repo = gitrepo;

    Switch to the FeatureB branch.

    branchDetails = switchBranch(repo,"FeatureB");
    branchDetails = 
    
      GitBranch with properties:
    
              Name: "FeatureB"
        LastCommit: [1×1 GitCommit]  (1376b77)

    Tip

    Use tab completion to get the list of available local branches in your repository.

    switchBranch command in the Command Window with tab completion applied on the branch name argument. Tab completion lists three local branches.

    Input Arguments

    collapse all

    Git repository, specified as a matlab.git.GitRepository object.

    Name of the local branch, specified as a string scalar or a character vector.

    Example: "BugIssue1032", 'FeatureB'

    Data Types: char | string

    Output Arguments

    collapse all

    Details of the branch, returned as a matlab.git.GitBranch object.

    Version History

    Introduced in R2023b