Last active
March 28, 2025 16:44
-
Star
(102)
You must be signed in to star a gist -
Fork
(57)
You must be signed in to fork a gist
-
-
Save erdincay/4f1d2e092c50e78ae1ffa39d13fa404e to your computer and use it in GitHub Desktop.
su GitHub (downloading all repositories from a given user)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
if [ -z "$1" ]; then | |
echo "waiting for the following arguments: username + max-page-number" | |
exit 1 | |
else | |
name=$1 | |
fi | |
if [ -z "$2" ]; then | |
max=2 | |
else | |
max=$2 | |
fi | |
cntx="users" | |
page=1 | |
echo $name | |
echo $max | |
echo $cntx | |
echo $page | |
until (( $page -lt $max )) | |
do | |
curl "https://api.github.com/$cntx/$name/repos?page=$page&per_page=100" | grep -e 'clone_url*' | cut -d \" -f 4 | xargs -L1 git clone | |
$page=$page+1 | |
done | |
exit 0 |
I did a similar thing with gh
command.
You can see it there.
"This is another solution":
page=$((page+1))
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you!
Only thing that tripped me up was that my terminal is authenticated with
ssh
, so I needed to switchclone_url
forssh_url
. And also I got a syntax error onuntil (( $page -lt $max )
and$page=$page+1
, I had to change them tountil [ $page -gt $max ]
andlet "page=page+1"
. And, finally, I was cloneing the repos in my org, not my user, so I setcntx=orgs
Whole script being