# remember to change the $gitHubApiKey # remember to change the $uri username $git="C:\Program Files\Git\bin\git.exe" $gitHubApiKey = convertto-securestring "ghp_sdafsdfsdaf..." -asplaintext -force function PullOrCloneAll($path="c:\src") { cd $path $repositories = FetchRepoList $i = 0 Foreach($repo IN $repositories) { $i += 1 Write-Host("{0,3} {1,-40} {2,-40}" -f ` $i, $repo.Name, $repo.Clone_Url) if(test-path $repo.Name) { Pull($repo); } else { Clone($repo); } } } function FetchRepoList() { $uri = "https://api.github.com:443/users/kbilsted/repos?page=&per_page=100" $all = @() $page = 0 $any = $TRUE while($any) { $any = $FALSE $page += 1 $urin = $uri.replace("?page=","?page="+$page) $repositories = (Invoke-RestMethod -Uri $urin -Token $gitHubApiKey) Foreach($repo IN $repositories) { $all += $repo $any = $TRUE } } Write-Host("Found " + $All.Count + " repositories") return $all | Sort-Object -property Name } function MayPullFromRepo() { $status = & $git status --porcelain if($status.Length -gt 0) { Write-Host -ForegroundColor red "!! LOCAL CHANGES - giving up" Write-Host("'"+$status+"'" + $status.Length) return $FALSE } $branch = & $git rev-parse --abbrev-ref HEAD if($branch -ne "master") { Write-Host -ForegroundColor red "!! NOT ON MASTER - giving up" return $FALSE } return $TRUE } function Pull($repo) { cd $repo.Name if(MayPullFromRepo) { $pullresult = & $git pull --ff-only --no-stat if($pullresult -ne "Already up-to-date.") { Write-Host -ForegroundColor green "" + $pullresult } } cd $path } function Clone($repo) { Write-Host("Clonning..."); & $git clone -v --recurse-submodules --progress $repo.Clone_Url $repo.Name # alternatively replace "Clone_Url" with "ssh_url" } (Get-Host).Version pullorcloneall