Skip to content

Instantly share code, notes, and snippets.

@ashmind
Last active September 3, 2016 21:52
Show Gist options
  • Save ashmind/f16a625032f0d31c17a2 to your computer and use it in GitHub Desktop.
Save ashmind/f16a625032f0d31c17a2 to your computer and use it in GitHub Desktop.
Set-StrictMode -Version 2
$ErrorActionPreference = 'Stop'
function Write-ColorOutput([Parameter(Mandatory=$true)] $inputObject, [System.ConsoleColor] $foregroundColor) {
$rawUI = $Host.UI.RawUI
$saved = $rawUI.ForegroundColor
try {
$rawUI.ForegroundColor = $foregroundColor
Write-Output $inputObject
}
finally {
$rawUI.ForegroundColor = $saved
}
}
Write-ColorOutput 'fetching origin' -ForegroundColor White
git fetch origin
Write-ColorOutput 'fetching upstream' -ForegroundColor White
git fetch upstream
$branches = git branch --all | % { $_ -replace '^[\s\*]*|\s+.+$','' }
$local = $branches | ? { $_ -notmatch '^remotes/' }
$upstream = $branches | ? { $_ -match '^remotes/upstream/(\S+)' } | % { $matches[1] }
$branches |
? { $_ -match '^remotes/origin/(.+)' } |
% { $matches[1] } |
? { $_ -ne 'HEAD' } |
sort -unique |
? { ($local -contains $_) -and ($upstream -contains $_) } |
% {
Write-ColorOutput "$($_):" -ForegroundColor White
Write-ColorOutput " checking out" -ForegroundColor White
git checkout $_
Write-ColorOutput " fast-forwarding" -ForegroundColor White
git merge upstream/$_ --ff-only
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment