Skip to content

Instantly share code, notes, and snippets.

@prasannavl
Created September 26, 2015 21:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save prasannavl/1e228133e197a9c92c88 to your computer and use it in GitHub Desktop.
Save prasannavl/1e228133e197a9c92c88 to your computer and use it in GitHub Desktop.
Clone all the repos for a given GitHub username.
function Clone-AllGitHubRepos
{
<#
.SYNOPSIS
Clone all GitHub Repositories of a given user.
.DESCRIPTION
Recursively clone all the repos for a given username.
.EXAMPLE
Clone-AllGitHubRepos -User "aspnet"
#>
[cmdletbinding()]
param(
[string]$User,
[string]$Destination,
[string]$ApiUrl = "https://api.github.com/users/$User/repos",
[string]$UserAgent = "Powershell"
)
Write-Verbose ("User: " + $User)
Write-Verbose ("ApiUrl: " + $ApiUrl)
$wc = New-Object System.Net.WebClient
if ($UserAgent) {
Write-Verbose ("Using user-agent: " + $UserAgent)
$wc.Headers.Add("User-agent", "$UserAgent")
}
$json = $wc.DownloadString($ApiUrl)
$res = ConvertFrom-Json $json
if ($Destination) {
Write-Verbose ("Using destination dir: " + $Destination)
cd $Destination
}
$res | % { Write-Verbose "$($_.name): $($_.html_url)"; git clone $_.html_url }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment