Skip to content

Instantly share code, notes, and snippets.

@luckyllama
Created July 13, 2012 20:56
Show Gist options
  • Select an option

  • Save luckyllama/3107394 to your computer and use it in GitHub Desktop.

Select an option

Save luckyllama/3107394 to your computer and use it in GitHub Desktop.
The Git-CompareBranchesMerged Cmdlet
# Assume we have a QA branch and a master (production) branch.
# The following feature branches have been merged with QA: A, B, C, D, E, F
# The following feature branches have been merged with master: A, B, C
PS> gcbm QA master
Listing branches in QA which are not in master
-> D
-> E
-> F
PS>
function Git-CompareBranchesMerged {
if ($args.Count -ne 2) {
"Usage: Git-CompareBranchesMerged branch1 branch2"
"This will list branches merged into branch1 which are not in branch2"
return
}
"Listing branches in $($args[0]) which are not in $($args[1])"
$merged1 = git branch -a --merged $args[0] | foreach { $_ -replace "remotes/origin/" -replace " " } | sort | unique
$merged2 = git branch -a --merged $args[1] | foreach { $_ -replace "remotes/origin/" -replace " " } | sort | unique
$currentColor = $Host.UI.RawUI.ForegroundColor
$Host.UI.RawUI.ForegroundColor = [System.ConsoleColor]"Red"
$branch1 = $args[0]
$merged1 | foreach {
$line1 = $_
$found = [Boolean]($merged2 | where { $_ -eq $line1 })
if (-not $found -and $line1 -replace " " -ne $branch1) {
$line1 = $line1 -replace "remotes/origin/"
"-> $line1"
}
}
$Host.UI.RawUI.ForegroundColor = $currentColor
}
Set-Alias gcbm Git-CompareBranchesMerged
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment