Skip to content

Instantly share code, notes, and snippets.

@schneidr
Created September 14, 2021 06:54
Show Gist options
  • Save schneidr/18ac65250a0bc98ffb0c124a93b949a1 to your computer and use it in GitHub Desktop.
Save schneidr/18ac65250a0bc98ffb0c124a93b949a1 to your computer and use it in GitHub Desktop.
List all branches of forks from a GitHub repository that don't exist on the root repository
param(
[Parameter(Mandatory=$true)]
[string]$rootRepo
)
$gh = 'C:\Program Files (x86)\GitHub CLI\gh.exe'
$rootBranches = (. $gh api /repos/$rootRepo/branches | ConvertFrom-Json).name
$repos = . $gh api /repos/$rootRepo/forks | ConvertFrom-Json
$repos | ForEach-Object {
$repo = $_.full_name
$branches = (. $gh api /repos/$repo/branches | ConvertFrom-Json).name
$differences = Compare-Object -ReferenceObject $rootBranches -DifferenceObject $branches |
Where-Object { $_.SideIndicator -eq '=>' } |
Select-Object InputObject,@{n='URL';e={ "https://github.com/$repo/tree/$($_.InputObject)" }}
if ($differences.Length -gt 0) {
Write-Host -ForegroundColor Green $repo
$differences | Format-Table -HideTableHeaders
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment