Test-GitBranch

Checks if a branch exists in a Git repository.

Syntax

Test-GitBranch [[-RepoRoot] <String>] [-Name] <String> [<CommonParameters>]

Description

The Test-GitBranch command tests if a branch exists in a Git repository. It returns $true if a branch exists; $false otherwise.

Pass the branch name to test to the Name parameter

Parameters

Name Type Description Required? Pipeline Input Default Value
RepoRoot String

Specifies which git repository to check. Defaults to the current directory.

false false (Get-Location).ProviderPath
Name String

The name of the branch.

true false

EXAMPLE 1

Test-GitBranch -Name 'develop'

Demonstrates how to check if the 'develop' branch exists in the current directory.

EXAMPLE 2

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

Demonstrates how to check if the 'develop' branch exists in a specific repository.