Last active
September 3, 2016 21:52
-
-
Save ashmind/f16a625032f0d31c17a2 to your computer and use it in GitHub Desktop.
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
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