Skip to content

Instantly share code, notes, and snippets.

View snobear's full-sized avatar
🎸

Jason Ashby snobear

🎸
  • NC
  • 04:31 (UTC -04:00)
View GitHub Profile
@snobear
snobear / clone-github-org-repos.sh
Created October 26, 2021 14:44
Clone all repos for a Github organization
# clone all public and private repos for a github org. user must have full access to repos.
USERNAME=someuser
ORGNAME=myorg
# personal access token
TOKEN=abc123tokenstringhere
# num repos to return per page - max 100
PERPAGE=100
BASEURL="https://api.github.com/orgs/${ORGNAME}/repos"
TOTALPAGES=`curl -I -i -u $USERNAME:$TOKEN -H "Accept: application/vnd.github.v3+json" -s ${BASEURL}\?per_page\=${PERPAGE} | grep -i link: 2>/dev/null|sed 's/link: //g'|awk -F',' -v ORS='\n' '{ for (i = 1; i <= NF; i++) print $i }'|grep -i last|awk '{print $1}' | tr -d '\<\>' | tr '\?\&' ' '|awk '{print $3}'| tr -d '=;page'`