create_branch
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
mb.create_branch(name=, ...)
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 ismain
by default.
Examples
Create a new branch
Create the my_branch
branch in Git:
mb.create_branch("my_branch")
Create a new branch off of old_branch
Branch from another branch using the from_branch
parameter:
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")