Skip to content

Instantly share code, notes, and snippets.

@guibranco
Created February 21, 2023 12:57
Show Gist options
  • Save guibranco/115ac4112aacaee9d8cee51ede89458f to your computer and use it in GitHub Desktop.
Save guibranco/115ac4112aacaee9d8cee51ede89458f to your computer and use it in GitHub Desktop.
Clone all repositories of an organization
#!/bin/bash
ORG_NAME="<<ORG>>"
ACCESS_TOKEN="<<GH_PAT>>"
TOTAL_PAGES=10;
eval `ssh-agent -s`
ssh-add ~/.ssh/*_rsa
for((PAGE=1;PAGE<=TOTAL_PAGES;PAGE++)); do
URL="https://api.github.com/orgs/${ORG_NAME}/repos?per_page=100&page=${PAGE}"
curl -H "Authorization: Bearer ${ACCESS_TOKEN}" ${URL} | ruby -rjson -e 'JSON.load(STDIN.read).each {|repo| %x[git clone #{repo["ssh_url"]} ]}'
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment