Skip to content

Instantly share code, notes, and snippets.

@qinjie
Forked from erdincay/sugh.sh
Created August 24, 2022 14:16
Show Gist options
  • Save qinjie/67d41685d33b9b06958d864a5529727d to your computer and use it in GitHub Desktop.
Save qinjie/67d41685d33b9b06958d864a5529727d to your computer and use it in GitHub Desktop.
su GitHub (downloading all repositories from a given user)
#!/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
@qinjie
Copy link
Author

qinjie commented Aug 24, 2022

Alternative Method:

Save following code in file clone.sh. Modify CNTX, NAME value and -u value to download private repositories.

CNTX={users|orgs}; NAME={username|orgname}; PAGE=1
curl -u {username|orgname} "https://api.github.com/$CNTX/$NAME/repos?page=$PAGE&per_page=100" |
  grep -e 'clone_url*' |
  cut -d \" -f 4 |
  xargs -L1 git clone

Run the script.

sh clone.sh

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment