Created
September 16, 2021 06:21
-
-
Save pkutaj/0f6a2ed0abb444bd7415685c2505f34b to your computer and use it in GitHub Desktop.
Show Git Branches Which are local-only, remote-only or both
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function match-branch ([switch]$local_only, [switch]$remote_only, [switch]$both) { | |
$localBranches = ((git branch -l) -replace "\*", "") -replace " ", "" | |
$remoteBranches = (((git branch -r) -replace "\*", "") -replace " ", "") -replace "origin/", "" | |
$branch_comparison = Compare-Object -ReferenceObject $localBranches -DifferenceObject $remoteBranches -IncludeEqual | |
| Select-Object @{Label = "branch"; Expression = { $_.InputObject } }, | |
@{Label = ”both”; Expression = { $_.SideIndicator -eq "==" } }, | |
@{Label = ”remote_only”; Expression = { $_.SideIndicator -eq "=>" } }, | |
@{Label = ”local_only”; Expression = { $_.SideIndicator -eq "<=" } } | |
if ($local_only) { $branch_comparison | Where-Object -Property "local_only" -EQ "true" | Select-Object branch } | |
elseif ($remote_only) {$branch_comparison | Where-Object -Property "remote_only" -EQ "true" | Select-Object branch} | |
elseif ($both) { $branch_comparison | Where-Object -Property "both" -EQ "true" | Select-Object branch } | |
else {$branch_comparison} | |
<# | |
.SYNOPSIS | |
Function displaying which git branches are local-only, remote-only and both local and remote | |
Called without a switch returns a table | |
To filter the table, use switches -local_only; -remote_only; -both | |
#> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment