createBranch - Create new Git branch - MATLAB (original) (raw)

Main Content

Create new Git branch

Since R2023b

Syntax

Description

[branchDetails](#mw%5F28150e9d-ed2b-4524-99e3-0f1e83f5443d) = createBranch([repo](#mw%5F21dda80e-6e31-4fbb-95f6-4da470a4905b%5Fsep%5Fmw%5F51431669-da82-405d-b33d-f5d5d0c7e853),[name](#mw%5F21dda80e-6e31-4fbb-95f6-4da470a4905b%5Fsep%5Fmw%5F076e1e3a-7a3f-4f61-bd75-9e5724d6e5eb)) creates a new branch in the Git™ repository repo with the name name from the most recent commit.

example

[branchDetails](#mw%5F28150e9d-ed2b-4524-99e3-0f1e83f5443d) = createBranch([repo](#mw%5F21dda80e-6e31-4fbb-95f6-4da470a4905b%5Fsep%5Fmw%5F51431669-da82-405d-b33d-f5d5d0c7e853),[name](#mw%5F21dda80e-6e31-4fbb-95f6-4da470a4905b%5Fsep%5Fmw%5F076e1e3a-7a3f-4f61-bd75-9e5724d6e5eb),StartPoint=[commitID](#mw%5Fade6b649-2645-4382-a92d-7e599ccef617)) creates a new branch in the Git repository repo with the name name from the specified commit.

example

Examples

collapse all

Navigate to your repository folder and create a repository object.

Create a new branch from the last commit of the currently checked-out branch.

branchDetails = createBranch(repo,"NewFeature")

branchDetails =

GitBranch with properties:

      Name: "NewFeature"
LastCommit: [1×1 GitCommit]  (1376b77)

Navigate to your repository folder and create a repository object.

Create a new branch from a commit and switch to the new branch.

newBranch = createBranch(repo,"InvestigateBug",StartPoint="1376b77"); switchBranch(repo,newBranch);

When you finish the work, delete the branch.

deleteBranch(repo,newBranch);

Input Arguments

collapse all

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

Example: "BugIssue1032",'FeatureB'

Data Types: char | string

Revision specifiers (ID) of start point commit, specified as a string scalar or a character vector. If you do not specify this input, the function creates a branch from the most recent commit.

If the start point is a remote branch, the createBranch function creates a local branch that tracks the remote branch automatically.

Commit IDs support short, full, and relative commits.

Example: "08a4c49","08a4c49d249a4dc3d998b473cdda186f1c05dfd0","origin/Dev"

Data Types: char | string

Output Arguments

collapse all

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

Version History

Introduced in R2023b