Git/Rebase-InsiderBranches.ps1
function Rebase-InsiderBranches { param( [Parameter(Mandatory=$false)] [string]$TargetCommit = 'master' ) $ErrorActionPreference = 'Stop' git fetch git checkout $TargetCommit #find all remote branches $RemoteInsiderBranches = Get-GitBranches | ? {$_.Contains('remotes/origin/build/insider')} foreach($RemoteInsiderBranch in $RemoteInsiderBranches) { #find the local branch tracking the remote branch $RemoteInsiderBranch = $RemoteInsiderBranch.Substring($RemoteInsiderBranch.IndexOf('origin')) $LocalInsiderBranches = git branch -vv | ? {$_.Contains(('{0}' -f $RemoteInsiderBranch))} foreach($LocalInsiderBranch in $LocalInsiderBranches) { $LocalInsiderBranch = $LocalInsiderBranch.TrimStart(' ') $LocalInsiderBranch = $LocalInsiderBranch.Substring(0,$LocalInsiderBranch.IndexOf(' ')) git branch -D $LocalInsiderBranch } git checkout $RemoteInsiderBranch -t #rebase onto master and force push to origin git rebase $TargetCommit git push -f } } Export-ModuleMember -Function Rebase-InsiderBranches |