Skip to content

Instantly share code, notes, and snippets.

@ymatsiuk
Last active July 6, 2023 11:46
Show Gist options
  • Save ymatsiuk/82e9efb11c73d75b4a5f38414b6d568c to your computer and use it in GitHub Desktop.
Save ymatsiuk/82e9efb11c73d75b4a5f38414b6d568c to your computer and use it in GitHub Desktop.
Clone all your organization's repositories in parallel

Pre-requisites:

  • parallel, jq, curl
  • GITHUB_TOKEN your personal github API token
  • ORG the name of your organization
  • REPO_TOTAL which is the total number of repositories your org owns (check curl below)

Get REPO_TOTAL

curl -L \
  -H "Accept: application/vnd.github+json" \
  -H "Authorization: Bearer ${GITHUB_TOKEN}"\
  -H "X-GitHub-Api-Version: 2022-11-28" \
  https://api.github.com/orgs/$ORG | jq -r '.public_repos + .owned_private_repos'

Run:

seq $REPO_TOTAL | parallel -j 8 clone_org.sh $ORG_NAME {#}

Note: scripts clones repositories into current directory under ORG_NAME/REPO_NAME

ORG=$1
PAGE=$2
curl -sL \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${GITHUB_TOKEN}"\
-H "X-GitHub-Api-Version: 2022-11-28" \
"https://api.github.com/orgs/$ORG/repos?per_page=1&page=$PAGE" | jq -r '.[]| "git clone \(.clone_url) \(.full_name)"' | sh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment