Clone all GitHub repositories of a user

Clone all GitHub repositories of a user

See my GitHub API current rate limits:

curl -sI "https://api.github.com/users/cookbooks/repos" | grep "^X-RateLimit"

Any left?
curl -sI "https://api.github.com/users/cookbooks/repos" | sed -nr 's/^X-RateLimit-Remaining: (.*)$/\1/p'

Or even simpler:
curl -s "https://api.github.com/rate_limit"

See how much data there is (paginated), for some user:

curl -sI "https://api.github.com/users/cookbooks/repos?page=1&per_page=100" | grep "^Link:"

Extract that (number of pages / last page number):

curl -sI $url | sed -nr 's/^Link:.*page=([0-9]+)&per_page=100>; rel="last".*/\1/p'

And now, the complete list extract:

usr="cookbooks";
url="https://api.github.com/users/${usr}/repos";
num=$(curl -sI "$url?page=1&per_page=100" | sed -nr 's/^Link:.*page=([0-9]+)&per_page=100>; rel="last".*/\1/p');
for ((i=1;i<=$num;i++)); do ( curl -s "$url?page=${i}&per_page=100" | grep "clone_url" | sed -nr 's/.*clone_url": "(.*)",/git clone \1/p' ); done >clone_allrepos_${usr}.sh

Execute created .sh when you are ready
./clone_allrepos_${usr}.sh
date 13. Jan 2013 | modified 28. May 2021
filename: Tip » Clone all GitHub Repos of a User