Skip to main content

mb.create_branch(name, ...)

Creates a new git branch and switches to it. An exception is raised if the branch already exists, or if the from_branch does not exist.

Parameters

  • name: str The name of the branch to create. Branch names must be lowercase, start with a letter, and only contain letters, numbers, hyphens, underscores and slashes.
  • from_branch: Optional[str] The name of the branch to use as the base when creating the new branch. If not specified the current branch is used, which is main by default.

Examples

Create a new branch

mb.create_branch("my_branch")

Create a new branch off of old_branch

Using from_branch:

mb.create_branch("my_branch", from_branch="old_branch")

Or similarly, switching to old_branch before creating a new branch:

mb.switch_branch("old_branch")
mb.create_branch("my_branch")

See also