New-GitBranch

Creates a new branch in a Git repository.

Syntax

New-GitBranch [[-RepoRoot] <String>] [-Name] <String> [[-Revision] <String>] [<CommonParameters>]

Description

The New-GitBranch creates a new branch in a Git repository and then switches to (i.e. checks out) that branch.

It defaults to the current repository. Use the RepoRoot parameter to specify an explicit path to another repo.

This function implements the git branch <branchname> <startpoint> and git checkout <branchname> commands.

Parameters

Name Type Description Required? Pipeline Input Default Value
RepoRoot String

Specifies which git repository to add a branch to. Defaults to the current directory.

false false (Get-Location).ProviderPath
Name String

The name of the new branch.

true false
Revision String

The revision where the branch should be started/created. A revision can be a specific commit ID/sha (short or long), branch name, tag name, etc. Run git help gitrevisions or go to https://git-scm.com/docs/gitrevisions for full documentation on Git's revision syntax.

false false HEAD

EXAMPLE 1

New-GitBranch -RepoRoot 'C:\Projects\LibGit2' -Name 'develop'

Demonstrates how to create a new branch named 'develop' in the specified repository.

EXAMPLE 2

New-GitBranch -Name 'develop

Demonstrates how to create a new branch named 'develop' in the current directory.