Skip to content

Instantly share code, notes, and snippets.

@ljtill
Last active August 16, 2021 18:06
Show Gist options
  • Select an option

  • Save ljtill/449fb3c27e8a8f830f640f4f8dddad7b to your computer and use it in GitHub Desktop.

Select an option

Save ljtill/449fb3c27e8a8f830f640f4f8dddad7b to your computer and use it in GitHub Desktop.
Provides the ability to list Git branches
function Get-GitBranch {
[CmdletBinding()]
param (
)
begin {
$branch = Invoke-Expression -Command "git branch --all"
$current = @()
$local = @()
$remote = @()
}
process {
switch -Regex ($branch) {
"^(?<current>(\*).*)" {
# Current
$current += $matches["current"]
}
"^(?<local>(\s|\*).(?!remotes).*)" {
# Local
$local += $matches["local"]
}
"^(?<remote>(\s).(remotes).*)" {
# Remote
$remote += $matches["remote"]
}
}
$branch = [PSCustomObject] @{
Current = $current
Local = $local
Remote = $remote
}
}
end {
return $branch
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment