Skip to content

Get‑GitLocalBranchName

viscalyxbot edited this page Sep 30, 2025 · 1 revision

SYNOPSIS

Retrieves the name of the local Git branch.

SYNTAX

Get-GitLocalBranchName [[-Name] <String>] [-Current] [<CommonParameters>]

DESCRIPTION

The Get-GitLocalBranchName command is used to retrieve the name of the local Git branch. It can either return the name of the current branch or search for branches based on a specified name or wildcard pattern.

EXAMPLES

EXAMPLE 1

Get-GitLocalBranchName -Name 'main'

Returns the branch that match exactly to the name 'main'.

EXAMPLE 2

Get-GitLocalBranchName -Name 'f/*'

Returns the names of all branches that match the wildcard pattern "f/*".

EXAMPLE 3

Get-GitLocalBranchName -Current

Returns the name of the current Git branch.

PARAMETERS

-Current

Indicates whether to retrieve the name of the current branch. If this switch parameter is present, the function will return the name of the current branch.

Type: SwitchParameter
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: False

-Name

Specifies the name or wildcard pattern of the branch to search for. If not provided, all branch names will be returned.

Type: String
Parameter Sets: (All)
Aliases:

Required: False
Position: 1
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

CommonParameters

This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.

INPUTS

None

This function does not accept pipeline input.

OUTPUTS

System.String

The name of the local Git branch.

NOTES

This function requires Git to be installed and accessible from the command line.

RELATED LINKS

Clone this wiki locally